While at one end of the caching spectrum, event based expiration of cache means we can have longer living cache lifetimes and smarter logic around cache lifetime in general; at the other end of spectrum, a new issue arises...

What if you expire content too frequently? For example, if a node's comments are very active, say a new comment every 1-5 minutes plus "likes"/recommends clicked for each comment or vote, if we expired the cache on each event, then we are more likely to get a higher number of cache misses than we'd like.

However, if we introduced a minimum cache lifetime, then we could "throttle" the number of expiration calls to cache within that minimum period lifetime. So continuing with the example above, if we set the throttle value to 3 minutes, then we could at least guarantee the cache would be used and not generated and purged virtually immediately.

I've implemented this solution using Drupal's cache expiration system. How it works is, when a URL is expired, it is set as a cid in its own cache bin with a lifetime of the throttled value. In this way, the cached item will naturally expire itself. Now when the URL derivatives are being generated, the expire module checks the cache and any items it can find in the cache, it discards from the URL expire list. This provides a light weight path expiration management system to keep track of how long since an item was last expired.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Josh Waihi’s picture

FileSize
3.35 KB

I've made one small change by moving the cache_set call to hook_page_build. This way I can start the "timer" for minimum cache lifetime from the time the page was generated, rather than last expired. In addition, if the cached item is present then no cache_set call is made. This is so that any additional variants of page cache will expire when the first original cache item was due to expire instead of making the original cached item live longer.

Josh Waihi’s picture

Title: Expiration Throttle » Implement an expiration throttle
FileSize
3.45 KB

One more small change ensuring that path alias throttles are also set.

Josh Waihi’s picture

Have added a permissions wrapper around the throttle to allow certain roles to bypass it. Use for content editors for example.

Spleshka’s picture

Status: Needs review » Needs work

Good idea! Please re-roll your patch for 7.x-2.x branch.

Spleshka’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

Forgot to change version number.

Spleshka’s picture

Status: Needs work » Postponed

Postpone this issue because of no progress.