function DrupalFileCache::delete_expired in File Cache 7
Delete expired cache entries.
2 calls to DrupalFileCache::delete_expired()
- DrupalFileCache::clear in ./
filecache.inc - Expire data from the cache. If called without arguments, expirable entries will be cleared from the cache_page and cache_block bins.
- DrupalFileCache::delete_flushed in ./
filecache.inc - Delete flushed cache entries.
File
- ./
filecache.inc, line 496 - DrupalFileCache class that implements DrupalCacheInterface.
Class
Code
function delete_expired($cache_flush = NULL) {
if (!isset($cache_flush)) {
$cache_flush = REQUEST_TIME;
}
$cache_size = 0;
foreach ($this
->all() as $filename) {
$pathname = $this->directory . '/' . $filename;
// gather statistics
$stat = @stat($pathname);
if ($stat === FALSE || is_dir($pathname)) {
continue;
}
$file_size = $stat['blocks'] >= 0 ? $stat['blocks'] * 512 : $stat['size'];
$cache_size += $file_size;
$content = @file_get_contents($pathname);
if ($content === FALSE) {
continue;
}
$cache = @unserialize($content);
if ($cache === FALSE) {
continue;
}
if ($cache->expire == CACHE_PERMANENT) {
continue;
}
$expiry_date = $cache->expire;
if ($cache->expire == CACHE_TEMPORARY) {
$expiry_date = $cache->created + variable_get('cache_lifetime', 0);
}
if ($expiry_date < $cache_flush) {
@unlink($pathname);
$cache_size -= $file_size;
}
}
// foreach $filename
return $cache_size;
}