Splitting this from #80951. The block_cache module in contrib allows for configurable expiry of block cache - this makes it easy to cache the Who's Online block and others that are frequently updated and/or expensive. This was left out of the core block caching system in D6, so opening up the discussion again for D7.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

catch’s picture

Title: Better cache expiry for blocks » Allow cache lifetime on a per_table and per table/cid basis
Category: feature » task
Status: Active » Needs review
FileSize
1.01 KB

Patch checks cache_lifetime_$table_$cid then cache_lifetime_$table then cache_lifetime. This would allow contrib to set cache lifetime on a per block basis. It would also allow just for basic stuff like having block caching set at 2 minutes and page caching at 30 minutes.

Was going to do this with a big ternary but Damz and Berdir in irc suggested the nested variable_get() calls instead. This might be done for free if we can get hook_variable_info() in with fallbacks.

moshe weitzman’s picture

Looks reasonable to me. Passes all tests, so I will rtbc after a couple of days unless ill comments arrive.

swentel’s picture

I like it, I created a D7 branch of block cache alter which allready profits if #186636: Block caching when node access modules are enabled. gets in. I'm hoping to try and apply this patch and see if I can make the module profit from it too - which it should normally.

Status: Needs review » Needs work

The last submitted patch failed testing.

catch’s picture

Status: Needs work » Needs review
FileSize
1.03 KB

Re-rolled.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

code looks nice and gives us some needed flexibility with cache expiry.

dww’s picture

Sure, that'd help. However, it's really just playing with your food so long as setting "minimum" cache lifetime actually sets a maximum cache lifetime, and plugable cache backends are free to interpret cache lifetimes as a hint, not a "this data should persist until X" directive. So, great, you can now have a lot more variables to tell the system "please keep block X around for an hour", but your cache is cleared all the friggin' time anyway, so what does it really help?

See #458808: Add a way to specify CACHE_PERMANENT for block caching for part of the story. I don't know where the issue is for "don't clear all cache entries after the minimum cache lifetime expires". There's #227228: cache_clear_all and cache_get fail to clear caches when Minimum cache lifetime is on but that's the other side of the bug. Minimum cache lifetime is just all kinds of broken. :(

Bigger picture, I don't know if there's already an issue for "make the plugable cache backend system support both volatile and nonvolatile caches", but we desperately need that. As it is now, the main alternative for core's cache.inc is memcache, which entirely assumes volatile caching. There's no way to specify certain cache tables or cids need to be treated nonvolatile. This patch here is sort of a step in the right direction, in that at least you can specify a fine-grained hint. But, so long as everything can assume all caching is volatile, we still can't (or shouldn't) use the core cache API for things like {cache_form}, {cache_update} (#220592-52: Core cache API breaks update.module: fetches data way too often, kills site performance, etc), etc. :(

catch’s picture

Assigned: Unassigned » catch

Losing track of my patches so need to start using the assigned field :(

Dries’s picture

Status: Reviewed & tested by the community » Needs work

I'm not sure this is the best solution -- it sounds a bit like a quick hack. For example, it makes the cache lifetime setting on the Performance settings page unreliable and confusing. I wonder if we need to skip this patch, and rework the cache lifetime code in a bit more drastic fashion? Based on #7, I think @dww might be sharing the same feelings. Let's discuss this some more.

catch’s picture

Having spoken to dww, I'm starting to think we need a "keep until" column in each cache table and remove minimum_lifetime altogether.

So in cache_set() you could specify a timestamp (say time() + 86400), and unless the cache entry gets specifically cleared by cid, or the entire cache table is truncated, it's kept for that long.

How exactly that value gets set, what happens when it's smaller than the $expires value, whether we give admins any control over it (i.e. page caching), I'm not sure about though.

catch’s picture

Title: Allow cache lifetime on a per_table and per table/cid basis » Add a 'keep until' column for cache tables
Version: 7.x-dev » 8.x-dev
Status: Needs work » Active

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: per_table_cid_cache_lifetime.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

I confirmed with catch that this is now outdated.