• PHP Video Tutorials

PHP - Memcache::replace() Function



Memcache::replace() function can replace the value of an existing item.

Syntax

bool Memcache::replace( string $key , mixed $var [, int $flag [, int $expire ]] )

Memcache::replace() function can be used to replace the value of an existing item with key. In case if item with such key doesn't exists, Memcache::replace() function can return false. For the rest, Memcache::replace() function behave identical to Memcache::set() function. We can also use memcache_replace() function.

Memcache::replace() function can return true on success or false on failure.

Example

<?php
   $memcache_obj = memcache_connect("memcache_host", 11211);

   /* Procedural API */
   memcache_replace($memcache_obj, "test_key", "some variable", false, 30);

   /* OO API */
   $memcache_obj->replace("test_key", "some variable", false, 30);
?>
Advertisements