Core classes finally moved

git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@14 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
aterekhov
2008-12-04 09:54:54 +00:00
parent a9a032c7fe
commit c6b8ae944f
12 changed files with 0 additions and 0 deletions

65
classes/Cache.class.php Normal file
View File

@ -0,0 +1,65 @@
<?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;
}
}
?>