I am new to codeigniter. I want to use file based caching. I do not know if I understood correctly.1. Declare the following in the parent controller - $this->load->driver('cache');2. $this->cache->file->save('foo', 'bar', 10); used to save the file, but I donβt know what the parameters of this function are and how to implement all this so that caching can be done.Please, help
$this->load->driver('cache');
$this->cache->file->save('foo', 'bar', 10);
http://codeigniter.com/user_guide/libraries/caching.html#example_usageThere is this in the manual - but this is a bit hidden in the example:
if ( ! $foo = $this->cache->get('foo')) { echo 'Saving to the cache!<br />'; $foo = 'foobarbaz!'; // Save into the cache for 5 minutes $this->cache->save('foo', $foo, 300); }
'foo' β the name of the variable you are going to cache$ foo -> cache variable. It could be anything300 β time in seconds (60 * 5) - set to 0 without expiration
Thus, IF $ foo is empty, the cache file is recreated, otherwise you can use $ foo to load data.
Further notes: http://codeigniter.com/user_guide/general/caching.html
A more flexible alternative might be this spark library: http://getsparks.org/packages/cache/showI use it and it is very well suited for file based caching.
https://www.codeigniter.com/userguide3/libraries/caching.html#example-usage
You can refer below URL. where all methods and examples related to the cache are mentioned.
There is also an example of using a third-party caching library such as Redis Cashing, etc.