Keith Devens .com |
Tuesday, August 19, 2008 | ![]() |
| Our Constitution was made only for a moral and religious people. It is wholly inadequate to the government of any... – John Quincy Adams | ||
|
| ← Ninjai back online | CSS3 Selectors → |

Simon Willison (http://simon.incutio.com/) wrote:
Harry Fuecks (http://www.phppatterns.com) wrote:
Think if you're using a template engine there's actually three types of caching you can perform.
The first is the template cache, which gets updated every time you change a template. With Smarty this means actually taking the template and "compiling" into native PHP.
The second is the type that output buffering can give you which works with the compiled template, takes the output it generates and caches that for a certain time period. PEAR::Cache_Lite can be a real time save there.
The third is HTTP caching, between the server and the client, which PHP can get involved with (using header() ) to instruct the browser when the page expires. Good general tutorial here
Keith (http://www.keithdevens.com/) wrote:
By far the easiest way of doing this is to implement caching as saving-a-file-somewhere, and regenerating the cache based on the file modified time AND whether or not the file exists.
Yeah, that's exactly how I was planning on doing it. The only issue with that is how to store the files. Is each cache filename a hash of the actual Request URI, or do I actually mirror the directory structure of the Request URI...
Also, you just cache the home page, but when you want to cache any page in general you have to have a way to figure out which content is on what page so that the page cache can be deleted when content on that page changes. Or I suppose you could just cache every page for no longer than a minute, in which case it wouldn't really matter.
Thanks Harry, I wasn't aware of PEAR::Cache_Lite - I'll check it out.
Harry Fuecks (http://www.phppatterns.com) wrote:
One other thing, re-reading your post, on events. The May Edition of php|arch has a take on event handling (you have to buy it though) which I guess is similar to "actions" - the event is a GET variable.
Think there's another type of event (basically what MS have done with ASP.NET) which is effectively "internal" in that parts of a page are aware of their state. If there's a submit button on a page, for example, and it get's click, the page is POSTed perhaps then on the page view which received the post, the button is notified that it's state has changed and so emits an "onClick" event. Something like that is harder to implement effectively although PEAR::QuickForm does something like this when a form is submitted back to the script thats using QuickForm and say the form failed to validate.
Anyway - just ranting away on a Saturday. Would be real interested to hear how you do - this is still kind a grey area for PHP methinks.
Sreejith wrote:
In ASP.Net when a page is cached the click event of a button control inside it can't work...how can this be solved?....
Feel free to post a comment below. Please see my comment policy.
Formatting Rules (No HTML):
Generated in about 0.159s.
(Used 8 db queries)

My blog uses a ludicrously simple caching mechanism on the front page (the most heavily trafficed page of the site) at the moment: it simply saves the generated page in a file somewhere using output buffering and checks the timestamp on the page whenever it is served, regenerating it if it is over a minute old. It's simple and a bit of a hack but it works well, although I've been warned it could suffer problems with race conditions (need to fix that some time).
The best explanation of conditional GET I've seen is here: http://fishbowl.pastiche.org/archives/001132.html
By far the easiest way of doing this is to implement caching as saving-a-file-somewhere, and regenerating the cache based on the file modified time AND whether or not the file exists. That way if you need to cached copy to expire right now you can just delete it and the system will regenerate it on the fly. My simple caching mecahnism for my blog works like that - whenever I post a new entry the "add entry" script deletes the front page cache causing it to be regenerated to include the new entry the next time someone visits it.