I’ve run into a slight problem with the Staticize caching plug-in I was using to speed up WordPress on this site. It seems that
$post->post_date isn’t correctly calculated on cached entries, even when you put them “outside” the cached page, and this screws up the time display on individual entries.
Here’s the details. On my permalinks pages, I display a relative publication time, e.g., “Posted 3 days 27 minutes ago”, using the Dunstan’s Time Since plug-in from Binary Bonsai. This works fine when the Staticize plug-in is disabled, and it works fine when Staticize is enabled, but only the first time the page is displayed, i.e., when it’s not served out of the cache. However, upon reloading, the page is served from cache, and the relative time displayed changes to the time since midnight.
Now, since this relative time will change, minute by minute, it has to be outside the cache, or it won’t update. Staticize has an easy way to accomplish this using simple tags. In my index.php page for WordPress, to display the relative time I have:
Posted <!--mclude timesince.php--><?php require('timesince.php'); ?><!--/mclude--> ago
timesince.php file is also pretty simple, just a quick calculation to emit the relative time:
<?php $entry_datetime = abs(strtotime($post->post_date) - (60*60*8)); echo time_since($entry_datetime); ?>
This technique tells the Staticize plug-in to process the include file every time, not just the first time. In theory, this would allow the relative timestamp to be calculated each time the page is served, and thus always be correct.
But I think that when Staticize is enabled, and determines that a page is in the cache,
$post isn’t fully set for that page, and so the value of
$post->post_date is meaningless, or it actually has no value at all, and so the functions above just calculate from the current date.
At any rate, for now the site doesn’t need caching to keep up, so I’ve turned off Staticize until I can decide if I care more about displaying the time since or about being ready for a traffic spike.