Closed (works as designed)
Project:
Drupal core
Version:
7.x-dev
Component:
base system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
18 Sep 2010 at 16:22 UTC
Updated:
18 Sep 2010 at 21:12 UTC
The idea of the #cache property of a render array is that it will manage caching of an element. It has an 'expire' member, which you would think would mean something. (My assumption is that someone using #cache and setting '#cache['expire'] would want it to expire. However, there's no provision for that in the code.
The attached one-liner adds that in.
Example: Without this patch the following would cache the element, but it would never expire:
$interval = 10;
$render_array = array( t('cache demonstration') => array(
'#markup' => t('The current time was %time when this was cached. Updated every %interval seconds', array('%time' => date('r'), '%interval' => $interval)),
'#cache' => array(
'keys' => array('render_example', 'cache', 'demonstration'),
'bin' => 'cache_page', // Not probably the best place for this.
'expire' => time() + $interval,
'granularity' => DRUPAL_CACHE_PER_PAGE | DRUPAL_CACHE_PER_ROLE,
),
),
);
| Comment | File | Size | Author |
|---|---|---|---|
| drupal.render_cache_invalidate.patch | 576 bytes | rfay |
Comments
Comment #1
moshe weitzman commentedIsn't it the responsibility of cache_get() to avoid returning expired items?
Comment #2
chx commentedNote that system cron forces expired items out of the cache AFAIK
Comment #3
moshe weitzman commentedthx chx. i guess rfay had not run cron recently.
we could ask cache_get() to check expired as well but that would be an significant API change for swappache cache backends. Probably D8.
Comment #4
rfaychx is right, of course. My patch would be far more predictable. Thanks for taking a look.