Файл: adultscript-2.0.3-pro/files/libraries/framework/cache/file.php
Строк: 49
<?php
defined('_VALID') or die('Restricted Access!');
class VCache_Driver_file extends VCache
{
public function __construct()
{
parent::__construct();
}
public function get($cache_id, $expire=NULL)
{
$path = $this->get_cache_file($cache_id);
clearstatcache();
if (file_exists($path)) {
if ($expire === 0) {
return unserialize(file_get_contents($path));
} else {
$time = time();
$limit = ($expire) ? ($time-((int)$expire)) : ($time-$this->lifetime);
if (filemtime($path) > $limit) {
return unserialize(file_get_contents($path));
} else {
$this->remove($cache_id);
}
}
}
return FALSE;
}
public function store($cache_id, $data, $expire=NULL)
{
$success = FALSE;
$path = $this->get_cache_file($cache_id);
$data = serialize($data);
if (($tmpfile = tempnam(CACHE_DIR, '.tmp')) &&
file_put_contents($tmpfile, $data) &&
rename($tmpfile, $path)) {
$success = TRUE;
}
if ($success && ($data == file_get_contents($path))) {
return TRUE;
}
return FALSE;
}
public function remove($cache_id)
{
$path = $this->get_cache_file($cache_id);
if (file_exists($path) && is_file($path)) {
if (!unlink($path)) {
return FALSE;
}
}
return TRUE;
}
public function gc()
{
return true;
}
public function clear()
{
$files = VFolder::files(CACHE_DIR);
foreach ($files as $file) {
@unlink($file);
}
}
public function test()
{
return is_writable(CACHE_DIR);
}
public function get_cache_file($cache_id)
{
return CACHE_DIR.'/'.$this->get_key($cache_id).'.cache.php';
}
}
?>