Memcache + PHP - Why data is not expiring?
memcached, php
Solution
Late to the game, but in your code it looks like you are passing "0" for the expiration (not "5"), which translates to "never expire" Specifically:
$memcache->set('foo', 'bar', 0, 5); // 5 seconds expiry
Should be:
$memcache->set('foo', 'bar', 5); // 5 seconds expiry
Unless I'm misunderstanding the PHP documentation located here, which shows that the set command takes three parameters:
public bool Memcached::set ( string $key , mixed $value [, int $expiration ] )
Edit: Whoops, I see that you're using the Memcache extension and not Memcached, which does have four parmaters. Perhaps try using the MEMCACHE_COMPRESSED constant instead of 0 to see if it works:
$memcache->set('foo', 'bar', MEMCACHE_COMPRESSED, 5); // 5 seconds expiry
Problem
I have a simple example where I set a value for 5 seconds. The problem is that after 5 seconds; I still get back a value when I expected 'false'. ``` $memcache = new Memcache; $memcache->connect('localhost', 11211) or die ("Could not connect"); $memcache->set('foo', 'bar', 0, 5); // 5 seconds expiry var_dump($memcache->get('foo')); // bar sleep(10); var_dump($memcache->get('foo')); // still shows bar ``` Here is the memcache server version Server's version: 1.4.13