Пример #1
0
 /**
  * Delete many keys from the cache at once
  *
  * @param array $keys An array of identifiers for the data
  * @return array of boolean values that are true if the key was successfully deleted, false if it didn't exist or
  * couldn't be removed
  */
 public function deleteMany($keys)
 {
     $cacheKeys = array();
     foreach ($keys as $key) {
         $cacheKeys[] = $this->_key($key);
     }
     $success = $this->_Memcached->deleteMulti($cacheKeys);
     $return = array();
     foreach ($keys as $key) {
         $return[$key] = $success;
     }
     return $return;
 }
Пример #2
0
 /**
  * 删除指定key的缓存,若$key===true则表示删除全部
  *
  * @param string $key
  */
 public function delete($key)
 {
     $this->_connect();
     if (true === $key) {
         if (Cache_Driver_Memcache::$_memcached_mode) {
             $status = $this->_memcache->flush(1);
         } else {
             $status = $this->_memcache->flush();
             if ($status) {
                 // We must sleep after flushing, or overwriting will not work!
                 // @see http://php.net/manual/en/function.memcache-flush.php#81420
                 sleep(1);
             }
         }
     } else {
         if (is_array($key)) {
             # 加前缀
             if ($this->prefix) {
                 foreach ($key as &$k) {
                     $k = $this->prefix . $k;
                 }
             }
             if (Cache_Driver_Memcache::$_memcached_mode) {
                 $status = $this->_memcache->deleteMulti($key);
             } else {
                 # 循环的删除
                 foreach ($key as $k) {
                     $this->_memcache->delete($k);
                 }
                 $status = true;
             }
         } else {
             $status = $this->_memcache->delete($this->prefix . $key);
         }
     }
     if (IS_DEBUG) {
         Core::debug()->info($key, 'memcache delete key');
     }
     return $status;
 }