示例#1
0
 public function testDeleteNotThere()
 {
     $memcache = new Memcache();
     $request = new MemcacheDeleteRequest();
     $item = $request->addItem();
     $item->setKey("delete_key");
     $response = new MemcacheDeleteResponse();
     $response->addDeleteStatus(DeleteStatusCode::NOT_FOUND);
     $this->apiProxyMock->expectCall('memcache', 'Delete', $request, $response);
     $this->assertFalse(memcache_delete($memcache, "delete_key"));
     $this->apiProxyMock->verify();
 }
示例#2
0
 /**
  * Deletes an item from the cache.
  *
  * @param string $key The key associated with the item to delete.
  *
  * @return bool true if the item was successfully deleted from the cache,
  *              false otherwise. Note that this will return false if $key is
  *              not present in the cache.
  */
 public function delete($key)
 {
     // Sending of a key of 'null' or an unset value is a failure.
     if (is_null($key)) {
         return false;
     }
     $request = new MemcacheDeleteRequest();
     $response = new MemcacheDeleteResponse();
     $request->addItem()->setKey($key);
     try {
         ApiProxy::makeSyncCall('memcache', 'Delete', $request, $response);
     } catch (Error $e) {
         return false;
     }
     $status_list = $response->getDeleteStatusList();
     return $status_list[0] == DeleteStatusCode::DELETED;
 }
 public function testDeleteNotThere()
 {
     $request = new MemcacheDeleteRequest();
     $item = $request->addItem();
     $item->setKey("widgets_delete_key");
     $item->setDeleteTime(10);
     $response = new MemcacheDeleteResponse();
     $response->addDeleteStatus(DeleteStatusCode::NOT_FOUND);
     $this->apiProxyMock->expectCall('memcache', 'Delete', $request, $response);
     $memcached = new Memcached();
     $memcached->setOption(Memcached::OPT_PREFIX_KEY, "widgets_");
     $this->assertFalse($memcached->delete("delete_key", 10));
     $this->assertEquals($memcached->getResultCode(), Memcached::RES_NOTFOUND);
     $this->apiProxyMock->verify();
 }
示例#4
0
 /**
  * deletes an array of $keys from the server.
  *
  * @param array $keys The keys to delete from the server.
  * @param int $time The time parameter is the amount of time in seconds the
  * client wishes the server to refuse add and replace commands for this key.
  *
  * @return bool true on success or false on failure.
  */
 public function deleteMulti($keys, $time = 0)
 {
     $request = new MemcacheDeleteRequest();
     $response = new MemcacheDeleteResponse();
     foreach ($keys as $key) {
         $key = $this->getPrefixKey($key);
         $item = $request->addItem();
         $item->setKey($key);
         $item->setDeleteTime($time);
     }
     try {
         ApiProxy::makeSyncCall('memcache', 'Delete', $request, $response);
     } catch (Error $e) {
         $this->result_code = self::RES_FAILURE;
         return false;
     }
     foreach ($response->getDeleteStatusList() as $status) {
         if ($status == DeleteStatusCode::NOT_FOUND) {
             $this->result_code = self::RES_NOTFOUND;
             return false;
         }
     }
     $this->result_code = self::RES_SUCCESS;
     return true;
 }