At both #425728: Add an "issue cockpit" block for project nodes and #371969: Move developer info into a block provided by cvs.module I ended up having to do some custom block caching before I could deploy those on d.o. The reason is that the core block caching system always calls cache_set() with CACHE_TEMPORARY. That results in the entire block cache getting cleared on every single cache_clear_all(), e.g. any new comment on the site. It's even worse if you set "minimum cache lifetime" which is also "maximum cache lifetime". :(
Many blocks don't change this often. In a lot of cases, the producer of a given block can be a lot smarter about when to invalidate the cache than this.
Can we add something in the block cache API that lets you not just specify the bit mask for which roles/pages/etc should count for the cache ID, but also a way to specify the cache lifetime? We could probably just do with another bit where 0 == CACHE_TEMPORARY (like we have now) and 1 == CACHE_PERMANENT.
Thoughts?
Comments
Comment #1
neRok commentedIm just going over some old core issues and trying to close them.
This blog posts indicates you can set cache life based on time
http://www.lullabot.com/blog/articles/beginners-guide-caching-data-drupal-7
Comment #2
dwwThanks for trying to clean up old issues. However, you misunderstood this request. The core block.module is calling cache_set(), not the modules providing blocks. So I'm asking for a way in the block API to tell it what value to pass as the final param for cache_set()...
I actually think this is more of an API oversight, not really a new feature, so I'll call it a task. ;)
I'm not yet sure what happened to blocks in D8, but if this is going to ever be fixed it has to happen there, first.
Comment #16
smustgrave commentedThank you for creating this issue to improve Drupal.
We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #17
dwwWow, blast from the past! Indeed, in D8+ ("modern Drupal"), when you're defining a block (Plugin), you can specify the #cache key and you get all sorts of control.
https://www.drupal.org/docs/drupal-apis/cache-api/cache-max-age is still sorta broken. See the Limitations of max-age section for details. But that's not what this issue was trying to solve.
Now that D7 is EOL and we're closing all the old issues, this one can die, too.
Thanks!
-Derek