|
Memcache::delete
Delete item from the server
()
Example 1312. Memcache::delete() example<?php Code Examples / Notes » memcache_deletesc00bz
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 LanguageMemcache::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 |