<?xml version="1.0" ?>
<rss version="2.0">
	<channel>
		<title>Keith's Weblog: Comments on &quot;Caching, Templates, and MVC&quot;</title>
		<description>Keith's Weblog: Comments on &quot;Caching, Templates, and MVC&quot;, posted on June 20, 2003</description>
		<link>http://keithdevens.com/weblog/archive/2003/Jun/20/CachingTemplatesMVC</link>

		<category>Programming</category>
		<category>This website</category>
		<language>en-us</language>
		<image>
			<link>http://keithdevens.com/weblog</link>
			<title>Keith Devens .com</title>
			<url>http://keithdevens.com/images/kbd.gif</url>
		</image>

		<item>
			<title>by Simon Willison</title>
			<link>http://keithdevens.com/weblog/archive/2003/Jun/20/CachingTemplatesMVC#comment2237</link>
			<guid isPermaLink="false">http://keithdevens.com/weblog/3992#comment2237</guid>
			<pubDate>Sat, 21 Jun 2003 08:55:01 +0000</pubDate>
			<description>&lt;p class=&quot;st-markup&quot;&gt;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).&lt;/p&gt;

&lt;blockquote class=&quot;st-markup&quot;&gt;&lt;p&gt;&amp;quot;It needs to handle things like last-modified, etags, conditional gets (I'm not even sure what those are)&amp;quot;&lt;/p&gt;&lt;/blockquote&gt;

&lt;p class=&quot;st-markup&quot;&gt;The best explanation of conditional GET I've seen is here: &lt;a href=&quot;http://fishbowl.pastiche.org/archives/001132.html&quot;&gt;http://fishbowl.pastiche.org/archives/001132.html&lt;/a&gt;&lt;/p&gt;

&lt;blockquote class=&quot;st-markup&quot;&gt;&lt;p&gt;How does the system do update notifications so that if new content is entered, the very next time the page loads that content can be shown, rather than waiting a few minutes for the cached copy to expire?&lt;/p&gt;&lt;/blockquote&gt;

&lt;p class=&quot;st-markup&quot;&gt;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 &lt;em&gt;right now&lt;/em&gt; 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 &amp;quot;add entry&amp;quot; script deletes the front page cache causing it to be regenerated to include the new entry the next time someone visits it.&lt;/p&gt;

</description>
		</item>
		<item>
			<title>by Harry Fuecks</title>
			<link>http://keithdevens.com/weblog/archive/2003/Jun/20/CachingTemplatesMVC#comment2241</link>
			<guid isPermaLink="false">http://keithdevens.com/weblog/3992#comment2241</guid>
			<pubDate>Sat, 21 Jun 2003 16:31:03 +0000</pubDate>
			<description>&lt;p class=&quot;st-markup&quot;&gt;Think if you're using a template engine there's actually three types of caching you can perform.&lt;/p&gt;

&lt;p class=&quot;st-markup&quot;&gt;The first is the template cache, which gets updated every time you change a template. With Smarty this means actually taking the template and &amp;quot;compiling&amp;quot; into native PHP.&lt;/p&gt;

&lt;p class=&quot;st-markup&quot;&gt;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. &lt;a href=&quot;http://pear.php.net/package-info.php?pacid=99&quot;&gt;PEAR::Cache_Lite&lt;/a&gt; can be a real time save there.&lt;/p&gt;

&lt;p class=&quot;st-markup&quot;&gt;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 &lt;a href=&quot;http://www.mnot.net/cache_docs/&quot;&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
		</item>
		<item>
			<title>by Keith</title>
			<link>http://keithdevens.com/weblog/archive/2003/Jun/20/CachingTemplatesMVC#comment2242</link>
			<guid isPermaLink="false">http://keithdevens.com/weblog/3992#comment2242</guid>
			<pubDate>Sat, 21 Jun 2003 16:38:03 +0000</pubDate>
			<description>&lt;blockquote class=&quot;st-markup&quot;&gt;&lt;p&gt;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.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p class=&quot;st-markup&quot;&gt;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...&lt;/p&gt;

&lt;p class=&quot;st-markup&quot;&gt;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. &lt;strong&gt;Or&lt;/strong&gt; I suppose you could just cache every page for no longer than a minute, in which case it wouldn't really matter.&lt;/p&gt;

&lt;p class=&quot;st-markup&quot;&gt;Thanks Harry, I wasn't aware of PEAR::Cache_Lite - I'll check it out.&lt;/p&gt;

</description>
		</item>
		<item>
			<title>by Harry Fuecks</title>
			<link>http://keithdevens.com/weblog/archive/2003/Jun/20/CachingTemplatesMVC#comment2243</link>
			<guid isPermaLink="false">http://keithdevens.com/weblog/3992#comment2243</guid>
			<pubDate>Sat, 21 Jun 2003 17:09:55 +0000</pubDate>
			<description>&lt;p class=&quot;st-markup&quot;&gt;One other thing, re-reading your post, on events. The &lt;a href=&quot;http://www.phparch.com/issuedata/2003/may/&quot;&gt;May Edition of php|arch&lt;/a&gt; has a take on event handling (you have to buy it though) which I guess is similar to &amp;quot;actions&amp;quot; - the event is a GET variable.&lt;/p&gt;

&lt;p class=&quot;st-markup&quot;&gt;Think there's another type of event (basically what MS have done with ASP.NET) which is effectively &amp;quot;internal&amp;quot; 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 &amp;quot;onClick&amp;quot; event. Something like that is harder to implement effectively although &lt;a href=&quot;http://pear.php.net/package-info.php?pacid=58&quot;&gt;PEAR::QuickForm&lt;/a&gt; does something like this when a form is submitted back to the script thats using QuickForm and say the form failed to validate.&lt;/p&gt;

&lt;p class=&quot;st-markup&quot;&gt;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.&lt;/p&gt;

</description>
		</item>
		<item>
			<title>by Sreejith</title>
			<link>http://keithdevens.com/weblog/archive/2003/Jun/20/CachingTemplatesMVC#comment10586</link>
			<guid isPermaLink="false">http://keithdevens.com/weblog/3992#comment10586</guid>
			<pubDate>Tue, 25 Mar 2008 04:08:18 +0000</pubDate>
			<description>&lt;p class=&quot;st-markup&quot;&gt;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?....&lt;/p&gt;

</description>
		</item>
	</channel>
</rss>
