File caching in the encoder

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

+4
source share
2 answers

http://codeigniter.com/user_guide/libraries/caching.html#example_usage
There 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 anything
300 β†’ 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/show
I use it and it is very well suited for file based caching.

+7
source

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.

0
source

All Articles