function get($key, $expires = null)
{
$dir = c::get('cache.dir');
$expires = $expires == null ? c::get('cache.expires') : $expires;
if (!is_dir($dir) or !is_writable($dir)) {
return false;
}
$cache_path = self::name($key);
if (!@file_exists($cache_path)) {
return false;
}
if (filemtime($cache_path) < time() - $expires) {
self::clear($key);
return false;
}
if (!($fp = @fopen($cache_path, 'rb'))) {
return false;
}
flock($fp, LOCK_SH);
$data = '';
if (filesize($cache_path) > 0) {
$data = unserialize(fread($fp, filesize($cache_path)));
} else {
$data = null;
}
flock($fp, LOCK_UN);
fclose($fp);
return $data;
}