Files
majestic/classes/Cache.class.php
aterekhov 988e49a197 svn:eol-style & svn:mime-type set
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@19 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
2008-12-05 13:32:38 +00:00

65 lines
1.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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;
}
}
?>