繁体   English   中英

如何设置缓存文件的到期日期?

[英]How to set an expiry for a cache file?

我想知道像doctrine-cache或zend-cache这样的缓存系统如果这些文件不在/ tmp文件夹中,就会为缓存文件设置一个到期日。 如何设置缓存文件的到期时间? 如果我想使用自己的缓存文件系统而不是使用doctrine或zend,如果我不想将它放在/ tmp文件夹中,如何设置它的到期日期?

缓存非常简单。 假设你有目录cache 您为变量$expire下的文件设置了到期时间

所以算法是

$file = "cache/cached.jpg";
$expire = 60 * 3600;

if (filectime($file) > time() + $expire)
{
   // reload file and invalidate cache
} else if (file_exists($file){
   // get from cache
} else {
  // get file and save it to cache then return  
}

但最好使用像http缓存那样的缓存,包括expire header,varnish等。

我建议使用缓存服务作为Memcached set函数有第三个参数 ,表示该值到期的秒数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM