6
我有一个相当昂贵的服务器调用,我需要缓存30秒。但似乎我无法让缓存过期。Drupal 7临时缓存项目不会过期
在下面的代码中,第一次缓存后,即使在time()+ 30秒之后,也不会超过$ return-> cache_data。
请注意,我甚至可以打印$ cache-> expire,它肯定会设置为30秒前的时间,并且不会更新。
我已经手动清除缓存很多次,以确认我得到相同的结果。
这样看起来有什么不对吗?
function mymodule_get_something($id) {
// set the unique cache id
$cid = 'id-'. $id;
// return data if there's an un-expired cache entry
// *** $cache ALWAYS gets populated with my expired data
if ($cache = cache_get($cid, 'cache_mymodule')) {
return $cache->data;
}
// set my super expensive data call here
$something = array('Double Decker Taco', 'Burrito Supreme');
// set the cache to expire in 30 seconds
cache_set($cid, $something, 'cache_mymodule', time() + 30);
// return my data
return $something;
}
感谢健康检查。 – Coder1
好方法。 +1 ...编辑:只是注意到它是克莱夫。当然这是一个好方法。 –
Hello Clive,“下一般缓存擦除”是什么? drush cc all会删除CACHE_TEMPORARY和CACHE_PERMANENT。当一般缓存刷卡发生时,有什么想法? –