Currently, the expiration time for data stored in cache_filter is hard-coded in filter.module as one day later than the current time. While this is reasonable for most types of data, it can be detrimental for expensive filterings which should only be performed once, unless the cache is specifically invalidated.
It would be helpful, then, if it was possible to specify how long data should be cached through hook_filter as a 'expires' $op. Conflict resolution (when multiple filters specify an expiration time) would be as follows:
$expire = null;
foreach ($filter_expires as $filter_expire) {
// Ignore null and string expiration times
if (!is_int($filter_expire)) continue;
// All expiration dates override these
if ($expire === null || $expire === CACHE_PERMANENT) {
$expire = $filter_expire;
}
// If new expiration is earlier than previous, use it
if ($expire > $filter_expire) {
$expire = $filter_expire;
}
// Shortest expiration time this cache can have without 'no cache'
if ($filter_expire === CACHE_TEMPORARY) {
// Technically, this is done by the above conditional, but since it's
// a magic number we can't use it
$expire = $filter_expire;
break;
}
}
// If no one specified anything, use default
if ($expire === null) $expire = time() + (60 * 60 * 24);
Of course, 'no cache' still overrules all of these. Comments?
Comments
Comment #1
gregglesdo you have a patch for this?
It seems useful. Also, I guess it's 7.x now...
Comment #2
ezyang commentedNo, but it would be trivial to make. Should I?
Comment #3
gregglesYes, it seems quite reasonable to me. It would be good, of course, if you could provide some statistics about how this impacts performance of the site, though that may be slightly difficult.
Comment #4
sunComment #5
wim leersAs of #2217877: Text filters should be able to add #attached, #post_render_cache, and cache tags,
check_markup()no longer does any caching, so this is no longer relevant.