【问题标题】:zend_cache absolute expiration timezend_cache 绝对过期时间
【发布时间】:2013-12-26 10:40:14
【问题描述】:

我正在使用带有zend 框架和zend_cache 的php。我有这几行代码:`

    $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);

我不想更新过期时间。有什么办法可以在不更新过期时间的情况下更新缓存?

【问题讨论】:

    标签: php zend-framework zend-cache


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-13
      • 1970-01-01
      • 1970-01-01
      • 2010-12-13
      相关资源
      最近更新 更多