How to Use Cache In Cake PHP

December 29, 2012
Posted by admin 3:02 PM

 Cache in cake PHP is used to reduce the load on the server as a temporary storage so that the each time a query from a database will not take time to execute the query if we store the data in cache when first time it execute from the database .So the cache is a temporary storage for our website to reduce the load time because the data not come from database ,it comes from cache that’s reduce the load time.

In cake PHP first we have to enable the cache from the app/config/core.php.
In core.php we have to uncomment the line Configure::write(‘Cache.disable’,true);

Now we can read ,write, delete with cache
1: Cache::read();      //the cache read used to read data from the cache.
$var_name=Cache::read(‘cloud’);
If($var_name !=false)
{
return $cloud;
}

2: Cache::write();        //the cache write to used to write the data in cache.
 $data=$this->Data->find();
 Cache::write(‘data’ , $ data);
 return $data;

3: Cache::delete() ;     //with cache delete we can remove cache object from the cache.
4: Cache ::config();     
// it is used to set some additional configuration to cache.
5: Cache::set();            // it is used to override some cache config settings for one operation.