Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Memcache Functions : Memcache::delete

Memcache::delete

Delete item from the server ()
bool Memcache::delete ( string key [, int timeout] )

Example 1312. 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);

?>

Code Examples / Notes » memcache_delete

sc00bz

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") . "
";
// get works because it was just added
echo "get: " . (($ret = $memcache->get("test")) !== false ? "'$ret'" : "f") . "
";
// delete works because it's in cache
echo "delete: " . ($memcache->delete("test", 1) ? "t" : "f") . "
";
// can't get "test" it is deleted
echo "get: " . (($ret = $memcache->get("test")) !== false ? "'$ret'" : "f") . "
";
// can't add "test" it is still in delete queue
echo "add: " . ($memcache->add("test", "value", 0, 60) ? "t" : "f") . "
";
echo "sleep(2)
";
// 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") . "
";
// delete works because it's in cache
echo "delete: " . ($memcache->delete("test", 1) ? "t" : "f") . "
";
// set removes "test" from delete queue and adds it to the cache
echo "set: " . ($memcache->set("test", "value", 0, 60) ? "t" : "f") . "
";
// get works
echo "get: " . (($ret = $memcache->get("test")) !== false ? "'$ret'" : "f") . "
";
echo "sleep(2)
";
// force output
ob_flush();
flush();
// wait 2 sec
sleep(2);
// get still works
echo "get: " . (($ret = $memcache->get("test")) !== false ? "'$ret'" : "f") . "
";
// delete works because it's in cache
echo "delete: " . ($memcache->delete("test") ? "t" : "f") . "
";
// add works because "test" wasn't added to the delete queue
echo "add: " . ($memcache->add("test", "value", 0, 60) ? "t" : "f") . "
";
// delete works because it's in cache
echo "delete: " . ($memcache->delete("test") ? "t" : "f") . "
";
?>
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


Change Language


Follow Navioo On Twitter
Memcache::add
Memcache::addServer
Memcache::close
Memcache::connect
memcache_debug
Memcache::decrement
Memcache::delete
Memcache::flush
Memcache::get
Memcache::getExtendedStats
Memcache::getServerStatus
Memcache::getStats
Memcache::getVersion
Memcache::increment
Memcache::pconnect
Memcache::replace
Memcache::set
Memcache::setCompressThreshold
Memcache::setServerParams
eXTReMe Tracker