I have a caching scenario which I’m not sure how to solve. I am able to cache static pages without a problem but am having a little trouble with dynamic pages.
In the dynamic page the logic goes something like this:
//part1
-some processing for the beg of the page (needed for part 3)
-echo some info
//part2
echo user specific menu + some user specific info
//part3
echo rest of the page
The problem is that if I cache the whole page, and then the cache is read, it is no good (
part2 will be incorrect since it depends on the user).
to cache a page, I just use
“ob_start();” at the beginning of the file, then save ob_get_contents() to a file and then “ob_end_flush();” at the end.
If the file already exists in cache and its not expired, i do: “include(file);” and “exit;”
I tried splitting the caching into two files but parts 2 and 3 depend on some php processing of part1 I’m having a hard time…
Does anybody have any ideas on how to solve this? Please let me know if I’m not being very clear and I will reformulate the question. Thank you!
APC/Redis/Memcached
If you could you should use APC(and/or Redis/Memcached) to cache your data because it is going to be WAAAAAAAAAAAAAAAAY faster(everything stays in MEMORY). If you want your website to perform good you should have APC(precompiled byte-code in MEMORY) installed anyway.
Cache_Lite
Else you should use the excellent Cache_Lite library to cache your data to a file. The introduction explains perfectly how to use it. If it all possible you should write to
/dev/shm/because this maps to MEMORY which is going to be way faster then Disc IO.Splitting Cache
You should have unique pieces(exclusively as large as possible would be best, but sometimes hard to keep track off) and then combine these pieces you need on that page. Each piece should have an unique ID off-course(for retrieval).