2

It seems that data expires as expected with Memcached, but the keys themselves never expire. Why are the keys sticking around after the value has nulled? When I run this code:

$frontCache = new Phalcon\Cache\Frontend\Data(array(
    "lifetime" => 30
));

//Create the Cache setting memcached connection options
$cache = new Phalcon\Cache\Backend\Memcache($frontCache, array(
    'host' => 'localhost',
    'port' => 11211,
    'persistent' => false
));

//Cache arbitrary data
$myNewRandomKey = generateNewRandomKey();
$cache->save($myNewRandomKey, array(1, 2, 3, 4, 5));

Taken from http://docs.phalconphp.com/en/latest/api/Phalcon_Cache_Backend_Memcache.html

I can succesfully save the array under the key $myNewRandomKey. I then run this code after the 30 second timeout has expired:

$keys = $cache->queryKeys();
print_r($keys);

And see that the key STILL EXISTS, though the data is NULL, where it was populated before the timeout expired. This seems only half-right to me. The key should have cleared too.

However, If I run $cache->delete($myNewRandomKey); the key will completely erase. Inconsistent!

Bottom line: If the keys don't expire or memcached is buggy, then will they grow and grow over time until it causes a different type of headache - a sysadmin headache?

Stats:
Windows 7 64bit
Apache 2.4.4
PHP 5.4.12
Memcached 1.4.4-14-g9c66c0
Memcache Apache extension version 2.2.7-5.4-VC9-x64 from http://www.anindya.com/category/windows/
Client: Phalcon PHP

Those are the versions, but I'm hoping that's irrelevant to the problem and that my expectations are wrong.

Cheers to all SO'ers!

SL

Tabby Laredo
  • 177
  • 1
  • 3
  • 9
  • On each request, you are inserting an element into the Memcached hash table with the same key. So each page request, the item is "renewed". You have to check to see that it doesn't exist first. – Ryan Oct 20 '14 at 23:20
  • No actually I'm generating a new key on each new tested request. I'll adjust the code above to make it more apparent. Keep in mind that the data does expire as expected, just not the key – Tabby Laredo Oct 20 '14 at 23:21
  • Hmmmm this looks like an oddity in Phalcon, it seems to null the result instead of deleting the keys. - See http://docs.phalconphp.com/en/latest/reference/cache.html#memcached-backend-example – Andy Oct 30 '14 at 11:37
  • I had this issue before (and a couple of odd error messages) with memcached. Use Redis if you can... – cvsguimaraes Feb 06 '15 at 18:55

0 Answers0