<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Invalidate Smarty Cache Using Cache Dependency Files - Slepi.NET</title>
    <link>http://slepi.net/entry/invalidate_smarty_cache_using_cache_dependency_files</link>
    <pubDate>Thu, 20 Nov 2008 21:53:08 -0600</pubDate>
    <description>Smarty is perhaps the most powerful and widely used PHP template engine available for PHP-based application developments. Though its usage has now been a bit pulled-aside by the rise of more advance frameworks such as Drupal or CakePHP, which come with their own template system implementations, for a "bare" template engine Smarty is still the favorite. I myself still use the combination of Smarty and PEAR (PHP Extension and Application Repository) for most of my PHP projects.
Taking it more than just a template engine, Smarty provides a built-in caching functionality. Smarty caches the server response, and that is in pure HTML. This is nice in the term of performance, especially for an extensive script-processing generated page (ie. script that does several database queries). As long as the cache hasn't been invalidated, in subsequent request of the page Smarty will simply return the pure HTML cache instead of executing the script every time.</description>
    <copyright>Copyrights 2008 Wiras Adi</copyright>
    <image>
      <url>http://www.slepi.net/images/slepinet-rss.png</url>
      <title>Invalidate Smarty Cache Using Cache Dependency Files - Slepi.NET</title>
      <link>http://www.slepi.net</link>
    </image>
    <item>
      <title>#1 Isn't this just a &amp;quot;multiple cache&amp;quot; (Antonio Bueno)</title>
      <link>http://slepi.net/entry/invalidate_smarty_cache_using_cache_dependency_files#response6</link>
      <description>I'm considering Smarty for my site and found your post when looking for information on Smarty caching. I like your file-based idea although I find it a bit restrictive (I miss including URL parameters, for example). 

But wouldn't this be a particular case of "multiple caches"?
&lt;a href="http://www.smarty.net/manual/en/caching.multiple.caches.php" title="http://www.smarty.net/manual/en/caching.multiple.caches.php" onclick="window.open(this.href);return false;" onkeypress="window.open(this.href);return false;" rel="nofollow external"&gt;http://www.smarty.net/manual/en/caching.multiple.caches.php&lt;/a&gt;

To replicate your solution I would combine file names and timestamps in a single "cache_id" (maybe a hash).</description>
      <pubDate>Tue, 29 Apr 2008 13:40:40 -0500</pubDate>
      <guid>http://slepi.net/entry/invalidate_smarty_cache_using_cache_dependency_files#response6</guid>
      <author>responses@slepi.net (Antonio Bueno)</author>
    </item>
    <item>
      <title>#2 #1 (Wiras Adi)</title>
      <link>http://slepi.net/entry/invalidate_smarty_cache_using_cache_dependency_files#response8</link>
      <description>Hello Antonio,

Actually, the technique I wrote in this post is merely intended to be a mechanism to refresh the cache at precisely when the page need to be refreshed. With cache_lifetime Smarty currently provides, cached page will refresh only when it reaches its lifetime in the pool. Thus there's a possibility that the page doesn't display a very actual data when some data changes happened within the lifetime of the cache. The technique tries to make the cache dependent to external events to trigger the refreshing.

On the other hand, multiple caching is a way to display different versions of a page conditionally, where one page has multiple displays depending on some parameters. With multiple caching, Smarty can cache all possible displays. But it still lack a kind of "real-time" cache expiration support. And this file-based cache dependency technique can also be applied in conjunction multiple caching, in a similar way as in ordinary caching mechanism.

About your idea to "inject" the file names and timestamps information in cache_id, don't you think that it would require relatively much works tweaking the Smarty system instead of just extend the class?

I haven't tried it yet, but I really think that it's a nice idea as it might lead to a cleaner application design than the one I proposed here.</description>
      <pubDate>Thu, 01 May 2008 20:24:53 -0500</pubDate>
      <guid>http://slepi.net/entry/invalidate_smarty_cache_using_cache_dependency_files#response8</guid>
      <author>responses@slepi.net (Wiras Adi)</author>
    </item>
  </channel>
</rss>
