我想知道,如果缓存文件不在/tmp文件夹中,像doctrine cache或zend-cache这样的缓存系统是如何设置缓存文件的过期时间的。如何设置缓存文件的过期时间?如果我想在php中使用我自己的缓存文件系统,而不是使用folder或zend,如果我不想将它放在/tmp文件夹中,我如何为它设置一个过期时间?
发布于 2016-09-13 18:58:27
缓存非常简单。假设您有目录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等。
发布于 2016-09-13 18:56:26
我建议使用缓存服务作为Memcached。有一个指向设置函数的third parameter,这意味着该值将在多长时间后过期。
https://stackoverflow.com/questions/39468166
复制相似问题