• PHP Video Tutorials

PHP - Memcache::add() Function



Memcache::add() function can add an item to server.

Syntax

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

Memcache::add() function can store a variable 'var' with 'key' only if such key doesn't exist at the server yet. We can also use the memcache_add() function.

Memcache::add() function can return true on success or false on failure. It can return false if such key already exists. For the rest Memcache::add() function behaves similarly to Memcache::set() function.

Example

<?php
   $memcache_obj = memcache_connect("localhost", 11211);
   memcache_add($memcache_obj, "var_key", "test variable", false, 30);  
   // procedural API
   $memcache_obj->add("var_key", "test variable", false, 30);  
   // OO API 
?>
Advertisements