Zend框架清除缓存(Zend Framework Clearing Cache)

2019-08-31 16:09发布

我使用这个代码缓存Zend框架的数组:

$frontendOptions = array(
    'lifetime' => 24 * 3600 * 7, // cache lifetime of 7 day
    'automatic_serialization' => true
);

$backendOptions = array(
    // Directory where to put the cache files
    'cache_dir' => APPLICATION_PATH .'/../tmp'
);

// getting a Zend_Cache_Core object
$cache = Zend_Cache::factory('Core',
    'File',
    $frontendOptions,
    $backendOptions);

$CacheName = ('VOUCHER_MANAGEMENT');

$CacheResult = $cache->load($CacheName);

if($CacheResult === false)
    //make cache
else 
    //use cache

现在,我怎么手动清除缓存?

Answer 1:

根据该文件中的一个单一的呼叫remove()方法就足够了,即删除特定的缓存项:

$cache->remove($CacheName);

如果你想清理过时缓存项,然后调用clean()方法:

$cache->clean(Zend_Cache::CLEANING_MODE_OLD);

要删除缓存中的所有项目:

$cache->clean(Zend_Cache::CLEANING_MODE_ALL);


文章来源: Zend Framework Clearing Cache