now right

git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@4 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
akulikov
2008-12-02 09:03:33 +00:00
parent f985cdaaf3
commit bbc1bf5c21
12 changed files with 912 additions and 0 deletions

58
Cache.class.php Normal file
View File

@ -0,0 +1,58 @@
<?php
/**
* Класс кеша.
* Отвечает за киширование результатов выполнения действий.
*
*/
final class Cache
{
private $cache_file;
private $cache_time;
function __construct($cache_name, $cache_time)
{
$this->cache_time = (int) $cache_time;
$this->cache_file = CACHE_PATH.'/'.$cache_name;
}
/**
* Сохраняет кэш в файл
*
* @return boolean - сохранил или нет
*/
function save($data)
{
if ($this->cache_time != 0) {
return (bool) file_put_contents($this->cache_file, $data);
}
return false;
}
/**
* Достает кэш из файла
*
* @return string - содержимое кеша
*/
function load()
{
return file_get_contents($this->cache_file);
}
/**
* Проверяет, закешированы ли данные с таким именем
*
* @return boolean - закеширован или нет
*/
function isCached()
{
if (! file_exists($this->cache_file)) {
return false;
}
if ($this->cache_time > 0 && $this->cache_time + filemtime($this->cache_file) < TIME_NOW) {
return false;
}
return true;
}
}
?>