Tuesday, March 2, 2010

PHP memcache

What is Memcached?(http://memcached.org/)

Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.
Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches. Its API is available for most popular languages.


Memcache module provides handy procedural and object oriented interface to memcached, highly effective caching daemon, which was especially designed to decrease database load in dynamic web applications.

sudo apt-get install php5-memcache

Example:

$memcache 
= new Memcache;$memcache->connect('localhost'11211) or die ("Could not connect");
$version $memcache->getVersion();
echo 
"Server's version: ".$version."
\n"
;
$tmp_object = new stdClass;$tmp_object->str_attr 'test';$tmp_object->int_attr 123;
$memcache->set('key'$tmp_objectfalse10) or die ("Failed to save data at the server");
echo 
"Store data in the cache (data will expire in 10 seconds)
\n"
;
$get_result $memcache->get('key');
echo 
"Data from the cache:
\n"
;
var_dump($get_result);
?>

Memcache Functions

Table of Contents





No comments:

Post a Comment