Reputation: 763
I am wondering how cache systems like doctrine-cache or zend-cache, set an expiry for cache files if those files are not in /tmp folder. How is possible to set an expiry for cache files? If I want to use my own cache file system with php rather than using doctrine or zend, how can I set an expiry for it if I don't want to place it in /tmp folder?
Upvotes: 1
Views: 3185
Reputation: 20286
The cache is pretty simple. Let's say you have directory cache
.
You set expiration time for files which are there under variable $expire
So the algorithm is
$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
}
but it's better to use caches that are there like http cache etc with expire header, varnish etc.
Upvotes: 2
Reputation: 788
I would recommend using cache service as Memcached. There is a third parameter to a set function, which means number of seconds after which the value will expire.
Upvotes: 1