Zend_Cache缓存文件消失
我有一个 zend 缓存,它存储数据库中的数组。缓存可以被读取和读取更新好了。但实际的缓存文件似乎在一天左右后就消失了。我认为添加 automatic_cleaning_factor = 0
可以解决这个问题,但事实似乎并非如此。
$frontendOptions = array(
'caching' => true,
'cache_id_prefix' => 'mysite_blah',
'lifetime' => 14400, # 4 hours
'automatic_serialization' => true,
'automatic_cleaning_factor' => 0,
);
$backendOptions = array(
'cache_dir' => "{$_SERVER['DOCUMENT_ROOT']}/../../cache/zend_cache/"
);
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
if(!$result = $cache->load('test_blah'))
{
// run SQL
...
$cache->save($my_array_from_db, 'test_blah');
}
else
{
$result = $cache->load('test_blah');
}
使用此缓存的页面不是很受欢迎,不确定这是否与它有关......有什么想法吗?
I have a zend cache which stores an array from the db. The cache can be read & updated fine. But the actual cache file seems to disappear after a day or so. I thought that adding automatic_cleaning_factor = 0
would solve this, but that doesn't seem to be the case.
$frontendOptions = array(
'caching' => true,
'cache_id_prefix' => 'mysite_blah',
'lifetime' => 14400, # 4 hours
'automatic_serialization' => true,
'automatic_cleaning_factor' => 0,
);
$backendOptions = array(
'cache_dir' => "{$_SERVER['DOCUMENT_ROOT']}/../../cache/zend_cache/"
);
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
if(!$result = $cache->load('test_blah'))
{
// run SQL
...
$cache->save($my_array_from_db, 'test_blah');
}
else
{
$result = $cache->load('test_blah');
}
The page which uses this cache isn't very popular, not sure if that has anything to do with it..... Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法解释为什么您的文件消失了,我认为您的示例中缺少某些内容,可能会删除缓存文件。不过,我可以提供一些可能对您有所帮助的注释...
我认为您误解了
automatic_cleaning_factor
参数。这不会阻止您的缓存过期。这只会禁止缓存前端自动清理在您调用save()
方法时可能已过期的任何缓存。当您
load()
缓存时,它仍然会进行有效性测试,如果无效,它将被忽略,并且将查询您的数据库以获取新数据。您可以将true
作为load()
的第二个参数传递,以忽略有效性测试。但是您可能应该将
生命周期
设置为很长的时间,而不是覆盖缓存验证,因为它的存在是有原因的。此外,此代码还可以简化:
至:
不需要
else
,因为缓存中的$result
已在if()
语句中分配。I cannot explain why your file is vanishing, I think something is missing from your sample that is probably removing the cache file. I can however have a few notes that might help you out...
I think you're misinterpreting the
automatic_cleaning_factor
parameter. This does not disable your cache from expiring. This only disables the cache frontend from automatically cleaning any cache that may have expired when you call thesave()
method.When you
load()
your cache it still gets tested for validity, and if invalid, it gets ignored and your database will be queried for fresh data. You can passtrue
as a second parameter on theload()
to ignore the validity test.However you should probably just set your
lifetime
to a very long time instead of overriding cache validation, because it's there for a reason.Also, this code can be simplified:
To:
The
else
is not needed because$result
from your cache is assigned in theif()
statement.