About Memcache :

The use of memcache is to speed-up the websites by using the memory space of our unused domains and store the database query results in the cache and minimize the application-database interaction.

How does it Work?

Before start implementing this,

First need to check whether the memcache is enabled in the web server or not. If it is not enabled, then enable it by uncomment the ‘extension=php_memcache.dll‘ in php.ini file in the server

Next, download the memcache executable file to install in server. Download link – http://code.jellycan.com/files/memcached-1.2.6-win32-bin.zip

Unzip the downloaded file, u will get a memcached executable file. Store that in a web server.

Then open the command promp and run this command c:/xampp/htdocs/memcached.exe -d install

then runc:/xampp/htdocs/memcached.exe -d start

Download the cache driver from here – http://d45jz936mo8n8.cloudfront.net/wp-content/uploads/2010/01/Cache.php_1.zip

Unzip and place the cache.php in system/libraries/cache.

Create an empty folder named cache on the location system folder.

Load the Cache driver in controller codeigniter application
$this->load->driver(‘cache’);

Add the following lines of code where needed to cache the query result.

$cache = $this->cache->get(‘cache_data’);
if($cache)
{
  $data = $this->cache->get(‘cache_data’);
}
else
{
   $data = $this->sample_model->get_data();
   $this->cache->save(‘cache_data’, $data, NULL, 3600);
}

While accessing the webpage, it will query the database for the first time, then the result will be stored in cache upto the refreshing time given in the save() function above.

So until the time exceeds, whenever the user refreshes the page, the application will not interact with the database. instead it will retrieve from cache and display.

This caching is applicable only for the select queries and the static updates.

If you enjoyed this article, Get email updates (It’s Free)
http://w3lessons.info/wp-content/uploads/2012/01/memcache-in-codeigniter11.pnghttp://w3lessons.info/wp-content/uploads/2012/01/memcache-in-codeigniter11-150x150.pngKarthikeyan KCodeigniterPHPcodeigniter,memcache,php
About Memcache : The use of memcache is to speed-up the websites by using the memory space of our unused domains and store the database query results in the cache and minimize the application-database interaction. How does it Work?Before start implementing this, First need to check whether the memcache is enabled in...