Hi there,

within our software we are using the TwoLevels Backend to cache our Models
and everything we get back from the DB.

The TwoLevels Backend uses APC as the fast backend (apc 3.1.3p1-2) and the
sqlite backend as slow backend (cause we need the tagging for deletion of
data). Now, in single user mode everything works as expected, but in our
live system we get some 'hiccups' from time to time.

Up to now we managed to find out what seems to happen.
Retrieving data from the cache sometimes retrieves 'old' data like:
apc_store('key', 'old data');
apc_store('key', 'new data');
and apc_fetch('key') retrieves 'old data' instead of the new data.
We didint manage to find out when this exactly happens, only that it does
happen from time to time.

Now, one of our ideas was to check how well the sqlite DB works with the
APC, and i did some simple tests, and see, there is a problem in that
matter. Imagine following use case:
1. apc_store('key', 'old data');
2. delete the sql DB by hand (rm /media/sqlite.db)
3. apc_store('key', 'new data');
4. apc_fetch('key') retrieves 'old data' again.

So i was able to generate a case which breaks exactly like it does in the
live system from time to time.

On my search for the error i also found that bug here:
http://pecl.php.net/bugs/bug.php?id=16814
which seems to be related to this matter. According to this it is not
possible to store the same key in the apc backend twice.
So what i imagine is, the sqlite db got some hiccups (whyever), then the
TwoLevels Backend thinks the key does not exist (cause it does not exist in
the sqlite db), adds an entry to the sqlite db, and then tries that on the
APC backend, which throws the "Potential cache slam averted for key
'45a514d8b95a11188e9376af5957b312'" error.

I finally tried to subclass the APC backend and patched the save method of
Zend_Cache_Backend_Apc.php like this:
public function save($data, $id, $tags = array(), $specificLifetime = false)
{
    $lifetime = $this->getLifetime($specificLifetime);

////// workaround
    $existingData = apc_fetch($id);
    if($existingData && $data != $existingData[0]){
        @apc_delete($id);
    }
////// end workaround

    $result = apc_store($id, array($data, time(), $lifetime), $lifetime);
    if (count($tags) > 0) {
        $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
    }
    return $result;
}

>From my understanding it should delete the apc entry, if it exists, and then
store the now data inside it.
But, if i try my usecase again, it still retrieves the old vaule, so i am a
bit stuck here.

Any Ideas on that matter? Am i looking into the wrong direction? Am i
missing something?

Thanks in Advance
Sven Richter

--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/Zend-Cache-Two-Levels-APC-and-Sqlite-tp3446836p3446836.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to