Memcache - values ​​removed from memcache reappearing

I use memcache to store Zend_Config (and other values). I set the values ​​as follows:

$memcache = new Memcache(); ... if (!$config = $memcache->get($memcache->unique_key.APPLICATION_DOMAIN."#config")) { ... $memcache->set($memcache->unique_key.APPLICATION_DOMAIN."#config", $config); } 

I delete the values ​​as follows:

 $memcache->delete($key); 

After I delete the values ​​from memcache, it appears correctly in the same connection as the remote one - calling $memcache->get($key) correctly gives me NULL . However, when I update the script (and establish a new connection to memcache), the data is returned as if the state of memcache had not been updated. I tried using replace instead (with some specific value), with the same effect - the value is not updated.

The call to $memcache->flush() works and removes everything from memcache, however I want to delete certain keys.

The manual page has a cryptic message from 5 years ago about incompatibilities between the versions of PECL and memcached (but this is from 5 years ago). Can someone explain to me what could happen?

I am using memcached 1.4.21 with memcache (PECL) 3.0.8 in PHP 5.6

+5
source share
2 answers

The problem is with using this:

 $list = array(); $allSlabs = $memcache->getExtendedStats('slabs'); foreach ($allSlabs as $server => $slabs) foreach ($slabs as $slabId => $slabMeta) foreach ($memcache->getExtendedStats('cachedump', (int) $slabId) as $entries) if (!empty($entries)) foreach ($entries as $key => $entry) if (strpos($key, $memcache->unique_key) === 0) { $value = $memcache->get($key); $list[$key] = is_string($value) && unserialize($value) ? unserialize($value) : $value; } 

(you will notice that it is not included in my original request, as it does not , but lists the keys / values ​​stored in memcached)

The problem with this functionality is that it seems to silently cause memcached to become read-only. Although the values ​​that are served on subsequent function calls are updated (as I think they are retrieved from local memory), the values ​​in the memcached service are not .

This behavior affects the current updated version of memcached - violation behavior was introduced in memcache (2.2.x)

I will keep the bounty open if anyone wants to explore this behavior

+7
source

one of the ways that works very well for me is to set the cache again with the same key, but set the expiration time a couple of seconds to "Now." This causes this key to expire in your cache. C # code is as follows:

 memcachedCache.Set(objectName, yourvalue, DateTime.Now.AddSeconds(-10)); 
0
source

All Articles