optimization with memcached - is it simple to implement?

memcached is service which provide memory cache storage. It can provide access to cached object via network and it is extrimly fast!

memcashed pecl module is a way which can be used to access cache storage. How it work? It more complicated instead Cache_Lite, but it is fastest. This fact can be explain: Cache_Lite use file system to store cache objects.

So, how PHP developer can use memcached module?
First memcached service need to be installed and configured. It can be done for Unix/Linux systems and for Windows NT/XP/Vista.
Second implement memcached usage to cache functionality like this:

$memcache = new Memcache;
$memcache->connect($memcached_host, $memcached_port) or die("Can not connect to memcached server");
if ($content = $memcache->get('content_key')) {
  $content = generated_complicated_content($params);
  $memcache->set('content_key', $content, 0, 30);
echo $content;

look really simple and very useful.

Trackback URL for this post: