Welcome Guest, Not a member yet? Register   Sign In
A question about Cache.
#1

[eluser]Блум[/eluser]
Hello,
I've red in the user guide that if I want to enable cache I have to put
Code:
$this->output->cache(n);
in the controller. This is okay, it works, but I meet some problems when trying to disable it.. I'll tell you what I mean.

I want to enable cache for unregistered users only, and I have something like
Code:
if ( ! $this->check_if_user_is('logged_user')) $this->output->cache(5);
In the controller, and it is working for ALL users, including the registered. The cached files by default are saved in system/cache/, and seems like when it finds some cache for the page that is not expired, it uses it, no matter if it is turned on.
Is this behaviour normal?

Thanks
#2

[eluser]Jelmer[/eluser]
Yes, the behavior is normal. The user guide states:
Quote:Caching can be enabled on a per-page basis, and you can set the length of time that a page should remain cached before being refreshed. When a page is loaded for the first time, the cache file will be written to your system/cache folder. On subsequent page loads the cache file will be retrieved and sent to the requesting user's browser. If it has expired, it will be deleted and refreshed before being sent to the browser.

Which in practice means that after the first caching no code is executed. That's because CI saves the output for a certain URI. When you request that URI CodeIgniter will look in your cache before anything of note has been loaded or executed. If there's a cache available for the URI requested it will be loaded and the system will just serve it up without ever looking at your controller again (until the cache expires of course).

You probably need a different kind of caching. You could try either Database caching or look into a caching library like mine (it's in my sig) or Phil Sturgeon's. They're very similar as Phil's is a fork of mine but we made different decisions on a couple of things. Just look what implementation suits you best.
#3

[eluser]Блум[/eluser]
Thanks Jelmer,
Your library seems to be exactly what I need.. :>




Theme © iAndrew 2016 - Forum software by © MyBB