2014-11-04 2 views
0

키를 삭제할 때 PHP Memcached &을 사용하고 있는데, 여전히 키를 검색 할 수 있습니다. 나는 무엇을 잘못 할 수 있 었는가?PHP Memcached 삭제가 작동하지 않습니다.

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")); 

실행 후 get은 여전히 ​​값을 반환합니다. 여기서 무슨 일이 일어나고 있는지 확실하지 않습니다.

function delete($key) { 
    self::instance()->_mc->delete($key); 
    unset(self::instance()->_cache[$key]); 
} 

을하지만 프로덕션 환경에서이 코드 디자인을 적용되지 않습니다

+0

'$ this -> _ cache [$ key]'란 무엇이며 어떻게 memcached와 관련이 있습니까? – Cheery

+1

... 캐시 된 것일까 요? 8) – Digitalis

+0

이제'$ this -> _ cache'에서 가져 와서'delete'에서 지우지 않기 때문에 더 많은 코드가 표시 될 때'get it는 실행 후에도 여전히 값을 반환합니다 '라고합니다. 아니면 스크립트에 대한 새로운 요청을 의미합니까? – Cheery

답변

1

또한 검색 중 방법의 측면에서 _cache 속성에서 캐시를 삭제해야합니다.

+0

이 작동하지만 왜이 코드 디자인을 프로덕션 환경에 적용하지 않을까요? – user2158382

+0

어떻게 unset (self :: instance() -> _ cache [$ key]);도 작동하지만'unset ($ current_cache [$ key]); '가 작동하지 않습니까? – user2158382

관련 문제