Controlling Cache on Views

#1
[eluser]FlashUK[/eluser]
I have a question about caching views from controllers. I have already searched the forums + google and haven't found a suitable answer yet.

In Smarty you could omit sections from being cached so that they could dynamically generate (link to documentation).
This was often used for things like display a users Username on a page when they are logged in, displaying a current timestamp, etc.

I want to know how you can do this with CodeIgniter's cache. I know you can set the timeout on the cache "$this->output->cache(n);" but how do I tell it not to cache certain sections in my views?

Thanks

#2
[eluser]nmweb[/eluser]
You can't. CI's caching mechanism isn't very useful for this kind of stuff. You better write your own.

#3
[eluser]FlashUK[/eluser]
Youch...

I thought this would have been a very common problem. Why is there no library in the Wiki that sorts this out?

#4
[eluser]sophistry[/eluser]
why don't you just pull in smarty as a library? then you can use its clever caching.

#5
[eluser]FlashUK[/eluser]
[quote author="sophistry" date="1216324388"]why don't you just pull in smarty as a library? then you can use its clever caching.[/quote]

I could do but then Smarty would over complicate CodeIgniter's simplicity. I like how things are handled with CI's view files.

#6
[eluser]sophistry[/eluser]
how about khcache? does this forum thread help?

#7
[eluser]FlashUK[/eluser]
Thanks, I shall check it out but it saw it says:

"allowing you to cache the output of smaller segments of code when no full page cache is available"

Along the right lines but I want code to be excluded outside of a full page cache Smile

Oh well, I shall have a bigger dig around.

#8
[eluser]sophistry[/eluser]
well, CI's default cache system is pretty brain dead - it caches the whole page at once, no ifs, ands, or buts.

so, khcache should allow you to construct something pretty easily to get what you want.

anyway, there are lots of options and lots of great code contributions. trouble is, you have to hang around a bit to get to know them all because the contributed resources are disorganized. but, you could just page through the IgnitedCode forum.

see this page of a thread from earlier this year on smarty and caching.

that thread page has this thread on sparks (an abandoned cache project with your specs).


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.