bool Memcache::set ( string key, mixed var [, int flag [, int expire]] )
Memcache::set() stores an item
var with key on the
memcached server. Parameter expire is expiration
time in seconds. If it's 0, the item never expires (but memcached server
doesn't guarantee this item to be stored all the time, it could be deleted
from the cache to make place for other items).
You can use MEMCACHE_COMPRESSED constant as
flag value if you want to use on-the-fly
compression (uses zlib).
Also you can use memcache_set() function.
See example below.
Note:
Remember that resource variables (i.e. file and connection descriptors)
cannot be stored in the cache, because they cannot be adequately
represented in serialized state.
Example 1. Memcache::set() example
<?php /* procedural API */
/* connect to memcached server */ $memcache_obj = memcache_connect('memcache_host', 11211);
/* set value of item with key 'var_key' using 0 as flag value, compression is not used expire time is 30 seconds */ memcache_set($memcache_obj, 'var_key', 'some variable', 0, 30);
echo memcache_get($memcache_obj, 'var_key');
?>
Example 2. Memcache::set() example
<?php /* OO API */
$memcache_obj = new Memcache;
/* connect to memcached server */ $memcache_obj->connect('memcache_host', 11211);
/* set value of item with key 'var_key', using on-the-fly compression expire time is 50 seconds */ $memcache_obj->set('var_key', 'some really big variable', MEMCACHE_COMPRESSED, 50);
echo $memcache_obj->get('var_key');
?>
Returns TRUE on success or FALSE on failure.
See also
Memcache::add(),
Memcache::replace().
Php memcache set Function syntax tag
memcache set php code on this is provided for your study purpose, it will guide you to know how create and design a website using php. use it to practice and train your self online
Php memcache set syntax tutorial
php tutorial guide and code design are for easy learning and programming. The code practice section provided at the top is for practising of this syntax. Use the code section up to practice your php programming online. Learning php is very easy, all you need is to use the examples on this site and practice them to perfect your skills.