Welcome Guest, Not a member yet? Register   Sign In
Codeigniter's built-in page cacher
#1

[eluser]Unknown[/eluser]
So, it's pretty cool, but... I wanna show cached pages to un-registered people such as spiders, and people who don't need registration.

When I use $this->output->cache(5) CI creates cache and shows it to every user. It makes problems because I have a toolbar for registered users, also this feature prevents correct log-in procedure.

How can I make CI to show cached pages only for clients who doesn't have
Code:
$this->session->userdata('log_in')
variable set, and generate pages as usual for clients that logged in?
#2

[eluser]pickupman[/eluser]
This issue has been discussed many times here in the forums. This is why you have some people develop other cache libraries in CI. As been discussed before, extend the core to check for user sessions before fetching a cached page. Or, as others have done, is grab one of those other libraries, and only cache the content that you need cached. The problem with CI's implementation is that it is all or nothing. I personally have used Phil Sturgeon's cache library and like it a lot. You can cache calls to functions in libraries, models, or any other data. Simple syntax and really solves the issue you are discussing. MP Cache is another popular partial caching library.
You could even use Phil's library to cache the output from a view, and retrieve for a not logged in user.
#3

[eluser]Aken[/eluser]
Can't you just put the cache command inside an IF statement, that checks to see if the user is not logged in? It's a bit of a band-aid depending on the data you're displaying and how often, but it should work.
#4

[eluser]pickupman[/eluser]
Quote:Can’t you just put the cache command inside an IF statement, that checks to see if the user is not logged in?
No, CI will first look in the cache folder for the page before doing any processing. If a page is found in the cache it will be output to the browser, and your controller is never loaded. That's why it caches the whole page rendered, so it doesn't have to re-render/process the pages again.
#5

[eluser]Aken[/eluser]
Ah yes, I forgot that it matches based on the URL. Nevermind!




Theme © iAndrew 2016 - Forum software by © MyBB