September 7, 2007 10:24 PM
Ok, I think I have the caching thing figured out. Seems that Smarty (which handles the dynamic publishing—and caching—for Movable Type) defaults to a one hour cache timeout. What Smarty does is write the time-stamp in a header on the cached file along with an expire time-stamp computed by adding an interval determined by the smarty variable
$cache_lifetime which defaults to 3600 seconds (or one hour). When retrieving a page, smarty compares the expire time with the time the cached file was built and retrieves the cached file only when the cache has not yet expired.
Why it does this is another matter. One hour seems either far too long or far too short for the life of a cache. It especially makes no sense in the context of Movable Type which seems to clear the cache whenever there is a change to the database, such as saving an entry—whether or not the entry is published—or making a comment (although, not, for some reason, when comments are deleted). Incidentally, I haven’t yet figured out how Movable Type achieves this. I can’t seem to find where in the code it flushes the cache or checks the modification date on the database, however I have empirically determined that this is the behavior.
This caching behavior especially makes no sense for me, since this blog changes, at most, daily. Fortunately, the default cache lifetime can be changed by editing the
smarty.class.php file (found at
mt/php/extlib/smarty/libs/). At the top of the file, which defines the smarty class, a bunch of default values for variables are set, some of which are overridden by Movable Type when it creates an instance of the smarty object and uses it to display dynamic content, notably the
$caching variable which defaults to 0 (off) is flipped on later if you have enabled caching enabled via publishing preferences.
$cache_lifetime = -1 results in a cache that never expires until the Movable Type database is changed, the setting that makes sense (to me, anyway) assuming that the only way the content displayed for a given page will change is if a change is made through Movable Type. This does bring up an important caveat however (although one I haven’t verified), which is that if you have dynamic content on a page that changes based on input other than the Movable Type database, it may not work, or may take some extra effort to ensure that it works.