Memcache::flush> <Memcache::decrement
Last updated: Mon, 28 Dec 2009

Memcache::delete

(PECL memcache:0.2-2.1.2)

Memcache::delete — Delete item from the server

Descrição

bool Memcache::delete ( string $key [, int $timeout ] )

Memcache::delete() deletes item with the key . If parameter timeout is specified, the item will expire after timeout seconds. Also you can use memcache_delete() function.

Parâmetros

key

The key associated with the item to delete.

timeout

Execution time of the item. If it's equal to zero, the item will be deleted right away whereas if you set it to 30, the item will be deleted in 30 seconds.

Valor Retornado

Retorna TRUE em caso de sucesso ou FALSE em falhas.

Exemplos

Exemplo #1 Memcache::delete() example

<?php

/* procedural API */
$memcache_obj memcache_connect('memcache_host'11211);

/* after 10 seconds item will be deleted by the server */
memcache_delete($memcache_obj'key_to_delete'10);

/* OO API */
$memcache_obj = new Memcache;
$memcache_obj->connect('memcache_host'11211);

$memcache_obj->delete('key_to_delete'10);

?>



User Contributed Notes
Memcache::delete
Sc00bz
19-Jul-2007 04:18
Timeout is the amount of time the key is in the delete queue. While the key is in the delete queue you can't add that key back into the cache, but you can use set. Set will remove the key from the delete queue and add it to cache.

Ex:
<?php
$memcache
= new Memcache();
$memcache->connect("127.0.0.1", 11211);

// add "test" with timeout 60 sec
echo "add: " . ($memcache->add("test", "value", 0, 60) ? "t" : "f") . "<br>";
// get works because it was just added
echo "get: " . (($ret = $memcache->get("test")) !== false ? "'$ret'" : "f") . "<br>";
// delete works because it's in cache
echo "delete: " . ($memcache->delete("test", 1) ? "t" : "f") . "<br>";
// can't get "test" it is deleted
echo "get: " . (($ret = $memcache->get("test")) !== false ? "'$ret'" : "f") . "<br>";
// can't add "test" it is still in delete queue
echo "add: " . ($memcache->add("test", "value", 0, 60) ? "t" : "f") . "<br>";
echo
"sleep(2)<br>";

// force output
ob_flush();
flush();
// wait 2 sec
sleep(2);

// add works because "test" is not in delete queue
echo "add: " . ($memcache->add("test", "value", 0, 60) ? "t" : "f") . "<br>";
// delete works because it's in cache
echo "delete: " . ($memcache->delete("test", 1) ? "t" : "f") . "<br>";
// set removes "test" from delete queue and adds it to the cache
echo "set: " . ($memcache->set("test", "value", 0, 60) ? "t" : "f") . "<br>";
// get works
echo "get: " . (($ret = $memcache->get("test")) !== false ? "'$ret'" : "f") . "<br>";
echo
"sleep(2)<br>";

// force output
ob_flush();
flush();
// wait 2 sec
sleep(2);

// get still works
echo "get: " . (($ret = $memcache->get("test")) !== false ? "'$ret'" : "f") . "<br>";
// delete works because it's in cache
echo "delete: " . ($memcache->delete("test") ? "t" : "f") . "<br>";
// add works because "test" wasn't added to the delete queue
echo "add: " . ($memcache->add("test", "value", 0, 60) ? "t" : "f") . "<br>";
// delete works because it's in cache
echo "delete: " . ($memcache->delete("test") ? "t" : "f") . "<br>";
?>

Output:
add: t
get: 'value'
delete: t
get: f
add: f
sleep(2)
add: t
delete: t
set: t
get: 'value'
sleep(2)
get: 'value'
delete: t
add: t
delete: t

Memcache::flush> <Memcache::decrement
Last updated: Mon, 28 Dec 2009