git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@19 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
65 lines
1.4 KiB
PHP
65 lines
1.4 KiB
PHP
<?php
|
||
/**
|
||
* Класс кеша.
|
||
* Отвечает за кеширование результатов выполнения действий.
|
||
*
|
||
* @copyright
|
||
* @link
|
||
* @package Majestic
|
||
* @subpackage Cache
|
||
* @since
|
||
* @version SVN: $Id$
|
||
* @filesource $URL$
|
||
*/
|
||
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;
|
||
}
|
||
}
|
||
|
||
?>
|