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

greggles’s picture

Version: 6.x-dev » 7.x-dev

do you have a patch for this?

It seems useful. Also, I guess it's 7.x now...

ezyang’s picture

Assigned: Unassigned » ezyang

No, but it would be trivial to make. Should I?

greggles’s picture

Yes, 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.

sun’s picture

Title: Allow filters/userland code to override page_filter expiration time » Allow custom cache expiration for filters / text formats
Version: 7.x-dev » 8.x-dev
wim leers’s picture

Status: Active » Closed (won't fix)

As 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.