#242 file cache를 PHP 파일로 변경.

This commit is contained in:
bnu 2014-01-05 02:30:17 +09:00
parent b29cf1fb67
commit 06a9e9fdac

View file

@ -49,7 +49,7 @@ class CacheFile extends CacheBase
*/ */
function getCacheFileName($key) function getCacheFileName($key)
{ {
return $this->cache_dir . str_replace(':', '/', $key); return $this->cache_dir . str_replace(':', '/', $key) . '.php';
} }
/** /**
@ -73,8 +73,11 @@ class CacheFile extends CacheBase
function put($key, $obj, $valid_time = 0) function put($key, $obj, $valid_time = 0)
{ {
$cache_file = $this->getCacheFileName($key); $cache_file = $this->getCacheFileName($key);
$text = serialize($obj); $content = array();
FileHandler::writeFile($cache_file, $text); $content[] = '<?php';
$content[] = 'if(!defined(\'__XE__\')) { exit(); }';
$content[] = 'return \'' . base64_encode(serialize($obj)) . '\';';
FileHandler::writeFile($cache_file, implode(PHP_EOL, $content));
} }
/** /**
@ -104,14 +107,16 @@ class CacheFile extends CacheBase
*/ */
function get($key, $modified_time = 0) function get($key, $modified_time = 0)
{ {
$cache_file = $this->getCacheFileName($key); $cache_file = FileHandler::exists($this->getCacheFileName($key));
$content = FileHandler::readFile($cache_file);
if($cache_file) $content = include($cache_file);
if(!$content) if(!$content)
{ {
return false; return false;
} }
return unserialize($content); return unserialize(base64_decode($content));
} }
/** /**