Currently the memcache module's only support for the minimum cache lifetime setting on the Drupal performance page actually enforces a MAXIMUM cache lifetime. I consider this a rather annoying bug, though I'm filing this as a feature request as the needed feature is proper support for minimum cache lifetime.

The attached patch is for the 6.x-1.x-dev version of this module -- it may apply cleanly to the 5.x version too, if not I will back port it as I want to see this feature in both versions of the module.

The minimum cache lifetime is implemented by tracking a global timestamp for each cache table -- instead of "flushing" the table, we update the timestamp. We then compare cache items with this global timestamp when we do a cache_get, and if the cached item is more than the "minimum cache lifetime" older than the flush timestamp, we return 0 to cause the item to be regenerated. As with Drupal core, we also make sure that the anonymous person caching the cache flush sees an updated version of the website -- however we track this in the $_SESSION rather than in $user->cache, as we need to track one timestamp for each table.

This improves upon the core minimum cache lifetime in the following ways: 1) it implements lazy cache invalidation (no DELETE * query), and 2) if, for example, the minimum cache lifetime is set to 10 minutes and the cache was last flushed 30 minutes ago, then the cache will be flushed immediately when the next content is posted. (With the core implementation, the cache isn't flushed for another 10 minutes, which imo is silly as we've already gone 30 minutes without a flush.) If there's been no cache flush for 30 minutes, the minimum cache lifetime is set to 10 minutes, and two comments are posted one after the other, the first will flush the cache, the second will lead to the cache "flushing" 10 minutes later properly enforcing the minimum cache lifetime.

This patch was sponsored by ParentsClick/ Lifetime Digital

CommentFileSizeAuthor
#7 memcache.inc_.362944.patch3.65 KBjaydub
memcache.inc_.patch2.58 KBjeremy

Comments

jvandyk’s picture

I am opposed to this patch on the grounds that I will have to redo my beautiful diagrams linked from the README. :P

jeremy’s picture

Nice diagrams!

The memcache-inc.png diagram is still correct if no minimum cache lifetime is specified! :)

My patch does not modify memcache-db.inc, as I never use that file / don't think it's useful, and hence tend to forget it exists. The README says that the minimum cache lifetime works if using memcache-db.inc, but from a quick read-through of the code I'm not convinced... it does flush the database version of the cache, but if memcache is running it seems we just end up enforcing a maximum cache lifetime again. In any case, that's outside the scope of my patch, which simply aims to get a minimum cache lifetime working for memcache.inc.

jeremy’s picture

I plan to commit this as we will be deploying this module on d.o for the upgrade this week -- any objections?

jvandyk’s picture

I haven't had a chance to work through this patch yet, but I have no objections (I'm a heavy user of memcache-db.inc) if you feel it's solid.

jeremy’s picture

imo, the logic in this patch should be ported to memcache-db.inc too, as it does not seem that the minimum cache lifetime works properly there either.

jeremy’s picture

Version: 6.x-1.x-dev » 5.x-1.x-dev
Status: Needs review » Needs work

Patch committed to 6.x-1.x-dev.

I now intend to backport this patch to 5.x-1.x-dev.

jaydub’s picture

Status: Needs work » Needs review
StatusFileSize
new3.65 KB

I took it upon myself to roll a patch for 5.x based on the code added in #6 as well as changes just reported in #539108: cache_set should not accept number of seconds as a valid expires-value as I'll be having to rollout Memcache for a Drupal 5 site and this looks like a worthwhile patch to port.

Everything works so far although I'll have to look into testing the actual minimum cache lifetime.

catch’s picture

Status: Needs review » Closed (won't fix)

Marking 5.x issues won't fix, this that branch is now unsupported.

vacilando’s picture

Does this mean that Memcache module for Drupal 6 and 7 do not support the minimum cache time?