Files
majestic/core/Cache.class.php
akulikov 62eef89248 core added
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@2 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
2008-12-02 08:59:06 +00:00

58 lines
1.3 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
/**
* Класс кеша.
* Отвечает за киширование результатов выполнения действий.
*
*/
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;
}
}
?>