views:

44

answers:

2

Hello,

I read this link :-

http://codeigniter.com/user_guide/general/caching.html

It is written that :-

When a page is loaded for the first time, the cache file will be written to your system/cache folder

and that we can cache a view by $this->output->cache(60);. But how does it actually work? What if regularly my users keep updating and deleting records as a result of which view changes very often. Will it show the modified data? or will the cache bring back the old stale data? (before inserts and updates)? If it automatically manages and brings fresh data from the database, then what is purpose of specifying the minutes in cache function?

Thanks in advance :)

+2  A: 

But how does it actually work?

If a cached version exists that is younger than the cache time, that cached version will be outputted.

Will it show the modified data?

Eventually yes, but with a lag of $cache_time

What if regularly my users keep updating and deleting records as a result of which view changes very often.

Reduce the cache time or don't use caching at all

Pete
Down-voting without a comment is sucky behaviour
Pete
+4  A: 

The way codeigniter's caching works generally is this:

A page request is made. Codeigniter (before very much of the framework has even been loaded) does a hash of the current url and if it finds that filename in the cache directory, it serves that.

The only way you can get fresh data is to manually delete the files. When codeigniter doesn't find the file from the hash it generated, it dynamically creates the page.

Codeigniter's implementation is called "full page" caching, and as so, is limited in it's usefullness. There's a partial caching library I've looked into from Phil Sturgeon here: http://philsturgeon.co.uk/code/codeigniter-cache

Honestly, for most projects, full page caching really isn't all that useful. In fact, the projects that I need full page caching I don't even leave that up to codeigniter (I leave it to the webserver: it's way faster).

I'd guess what you're looking for is a partial caching method; most people would prefer this. Look into APC if you're using a single server or Memcached if you have multiple servers.

Good Luck.

Matthew