Extends
lithium\core\Object
Read value(s) from the cache.
Parameters
- string $key The key to uniquely identify the cached item.
Returns
closure Function returning cached value if successful, `false` otherwise.Source
public function read($key) {
$path = $this->_config['path'];
return function($self, $params) use (&$path) {
extract($params);
$path = "$path/$key";
$file = new SplFileInfo($path);
if (!$file->isFile() || !$file->isReadable()) {
return false;
}
$data = file_get_contents($path);
preg_match('/^\{\:expiry\:(\d+)\}\\n/', $data, $matches);
$expiry = $matches[1];
if ($expiry < time()) {
unlink($path);
return false;
}
return preg_replace('/^\{\:expiry\:\d+\}\\n/', '', $data, 1);
};
}