Welcome Guest, Not a member yet? Register   Sign In
CI Caching almost useless?
#11

[eluser]ntheorist[/eluser]
i've started confronting this issue as well, especially with the user data or other session/user-specific data. I've been playing with colin williams' straightforward template library, where you specify a template with regions. Many times those regions will be views, but regardless, it presents an opportunity to cache per region.

so if http://www.domain.com/profiles/edit used a template with the regions head,userpanel,mainmenu,sidemenu,body,footer, you could say, mark mainmenu,sidemenu and footer to be cached. The cache dir could look like:

./cache/{controller}/{method}/{region}.php

or as in the example

./cache/profiles/edit/mainmenu.php
./cache/profiles/edit/sidemenu.php
./cache/profiles/edit/footer.php

then when the library loads, it could be tweaked to load any specified cache files right away (or delete them if expired), or through additional functionality used in your controllers :

Code:
// Loads cached data into region on TRUE, FALSE if exipired, and then caches on write if marked to do so
if( ! $this->template->cached($region} )
{
     .. run data processes
     $this->template->write_view($region, $data); // etc..
}

this is all just theory now since i haven't put it into practice, and i haven't dug into memcached as an alternative yet, which may work better as it has built in functionality. Perhaps that could be the caching method employed instead of disk writes to the file pattern above. Either way imna try to tackle this one and post what i figure out.

cheers,

n
#12

[eluser]Phil Sturgeon[/eluser]
Why store the time it was created in the file name? That means you could have multiple cache files and you would have trouble finding the file anyway.

Store files like this:

./cache/profiles/edit/mainmenu.php.cache
./cache/profiles/edit/sidemenu.php.cache
./cache/profiles/edit/footer.php.cache

And then use filemtime() on the files to see when they were modified. If they are old or non existent, just write over the top.
#13

[eluser]ntheorist[/eluser]
lol Phil, you are always one step ahead of me! yeah mfiletime would work better, i spose i should check before posting code on the fly. Tongue I updated my post.

what's the reason for using the .cache extension? would it suffice to use the EXT constant?
#14

[eluser]ntheorist[/eluser]
Hrm well this is kinda new territory for me. You'd think that any form of block level caching would have more overhead than caching the full page.

The easiest way to avoid it is probably to just not cache entire pages that use the database and rely on database caching instead. That's obviously not the most scalable solution though, as you point out, with more simultaneous users you'd be putting a higher load on the DB for retrieving the same data over and over.

Another method would be to store whatever 'live' objects in a session object and have it update only on login/cookie read or upon a specific interval, or maybe stored as json and inserted with js/jquery. Either way you would need to execute some code to check for the object and if not there, regenerate it and send it to/call from the cached page. Perhaps the CI way would be to write a pre_system hook, which fires just before CI caching.

As far as i can tell, the next best thing from static file caching is straight php. The cache files would be fully rendered XTML except for basically echo, foreach loops etc. working with the chached object. As long as you could avoid having to load all the helpers, classes etc you'd be sparing yourself a lot of processing. I'm trying to do something similar, where processing builds essentially a flat php file using basic functions to format/produce output from a data source. Then navigating to the page takes you to that.
#15

[eluser]Phil Sturgeon[/eluser]
Lets continue this conversation in a thread started by Yorick with a less abrasive title. I have suggested a solution to solve all our partial caching needs, please take a look.

Partial Caching, the way it should be

ntheorist: I use .cache over .php so it wont leave executable PHP on the server when it doesn't need to. It is also a personal habit. Some people like to use .tmp, whatever.
#16

[eluser]supahero[/eluser]
i'm using CI caching for my mp3 website. it's powerfull enough. my web have more than 8000UV/day and bandwidth > 2GB/day. but don't forget to delete your old cache files with cron schedule




Theme © iAndrew 2016 - Forum software by © MyBB