[英]Php Memcached delete not working
I am using PHP Memcached & when I delete a key, I can still retrieve the key. 我正在使用PHP Memcached,并且删除密钥时,仍然可以检索该密钥。 What could I be doing wrong?
我可能做错了什么?
function __construct() {
$this->_cache = array();
// if we have memcache support, load it from CACHE_POOL
//
if (class_exists('Memcached')) {
$this->_mc = new Memcached('CACHE_POOL');
$servers = $this->_mc->getServerList();
if (empty($servers)) {
//This code block will only execute if we are setting up a new EG(persistent_list) entry
$this->_mc->setOption(Memcached::OPT_RECV_TIMEOUT, 1000);
$this->_mc->setOption(Memcached::OPT_SEND_TIMEOUT, 3000);
$this->_mc->setOption(Memcached::OPT_TCP_NODELAY, true);
$this->_mc->setOption(Memcached::OPT_PREFIX_KEY, "md_");
$this->_mc->addServers(self::$_MEMCACHE_IPS);
}
$current_cache = $this->_mc->get(self::CACHE_KEY);
if ($current_cache) {
$this->_cache = array_merge($this->_cache, $current_cache);
}
}
}
function delete($key) {
self::instance()->_mc->delete($key);
}
function getSafe($key) {
return isset($this->_cache[$key]) ? $this->_cache[$key] : FALSE;
}
self::instance()->delete("test");
echo(self::instance()->getSafe("test"));
After running this, the get still returns a value. 运行此命令后,get仍返回一个值。 Not sure what is going on here.
不知道这是怎么回事。
You should also delete cache from _cache property in terms of the retrieving method: 您还应该根据检索方法从_cache属性中删除缓存:
function delete($key) {
self::instance()->_mc->delete($key);
unset(self::instance()->_cache[$key]);
}
But do not apply this code design in your production environment. 但是不要在您的生产环境中应用此代码设计。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.