zend_cache绝对到期时间

时间:2013-12-26 10:40:14

标签: php zend-framework zend-cache

我正在使用php和zend框架以及zend_cache。我有这些代码行:`

    $frontendOptions = array ('lifetime' => 12 * 3600, 'automatic_serialization' => true );
    $backendOptions = array ('cache_dir' => APPLICATION_PATH . '/../tmp');
    $cache = Zend_Cache::factory ( 'Core', 'File', $frontendOptions, $backendOptions );

    $CacheName = ('CACHE_NAME');
    $CacheResult = $cache->load ( $CacheName );
    if($CacheResult==false)
        echo 'no cache or chache is expired';
    else 
        var_dump($CacheResult);`

问题在于,当我使用这样的保存功能时:

$cache->save($data,$CacheName);

我不希望过期时间更新。有没有办法更新缓存而不更新其到期时间?

1 个答案:

答案 0 :(得分:1)

首先,ZF1的Zend_Cache将给定生命周期存储为固定的到期时间。 因此,您只需要根据当前时间和到期时间计算当前生命周期:

$lifetime = $expirationTime - time();
if ($lifetime > 0) {
    $cache->save($data, $id, $tags, $lifetime);
}

PS:在ZF2中,您必须检查存储是否在当前时间,mtime和给定TTL(如文件系统)的基础上或在存储的固定到期时间(如memcache / apc)的基础上检查到期。

相关问题