Source for file Ethna_Plugin_Cachemanager_Localfile.php
Documentation is available at Ethna_Plugin_Cachemanager_Localfile.php
// vim: foldmethod=marker tabstop=4 shiftwidth=4 autoindent
* Ethna_Plugin_Cachemanager_Localfile.php
* @author Masaki Fujimoto <fujimoto@php.net>
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* キャッシュマネージャクラス(ローカルファイルキャッシュ版)
* @author Masaki Fujimoto <fujimoto@php.net>
/**#@+ @access private */
* キャッシュに値が設定されている場合はキャッシュ値
* が戻り値となる。キャッシュに値が無い場合やlifetime
* を過ぎている場合、エラーが発生した場合はEthna_Error
* @param string $key キャッシュキー
* @param int $lifetime キャッシュ有効期間
* @param string $namespace キャッシュネームスペース
function get($key, $lifetime =
null, $namespace =
null)
$namespace =
is_null($namespace) ?
$this->namespace :
$namespace;
$cache_file =
$this->_getCacheFile($namespace, $key);
||
($st =
stat($cache_file)) ===
false) {
if (($st[9]+
$lifetime) <
time()) {
$fp =
fopen($cache_file, "r");
$r =
flock($fp, LOCK_EX|
LOCK_NB);
if ($st ==
false ||
$n >
5) {
$value =
fread($fp, $st[7]);
* @param string $key キャッシュキー
* @param string $namespace キャッシュネームスペース
* @return int 最終更新日時(unixtime)
$namespace =
is_null($namespace) ?
$this->namespace :
$namespace;
$cache_file =
$this->_getCacheFile($namespace, $key);
||
($st =
stat($cache_file)) ===
false) {
* @param string $key キャッシュキー
* @param int $lifetime キャッシュ有効期間
* @param string $namespace キャッシュネームスペース
function isCached($key, $lifetime =
null, $namespace =
null)
$namespace =
is_null($namespace) ?
$this->namespace :
$namespace;
$cache_file =
$this->_getCacheFile($namespace, $key);
||
($st =
stat($cache_file)) ===
false) {
if (($st[9]+
$lifetime) <
time()) {
* @param string $key キャッシュキー
* @param mixed $value キャッシュ値
* @param int $timestamp キャッシュ最終更新時刻(unixtime)
* @param string $namespace キャッシュネームスペース
function set($key, $value, $timestamp =
null, $namespace =
null)
$namespace =
is_null($namespace) ?
$this->namespace :
$namespace;
$dir =
$this->_getCacheDir($namespace, $key);
if ($r ==
false &&
is_dir($dir) ==
false) {
$cache_file =
$this->_getCacheFile($namespace, $key);
$fp =
fopen($cache_file, "a+");
$r =
flock($fp, LOCK_EX|
LOCK_NB);
// this could suppress warning
touch($cache_file, $timestamp);
* @param string $key キャッシュキー
* @param string $namespace キャッシュネームスペース
function clear($key, $namespace =
null)
$namespace =
is_null($namespace) ?
$this->namespace :
$namespace;
$cache_file =
$this->_getCacheFile($namespace, $key);
function _getCacheDir($namespace, $key)
// intentionally avoid using -2 or -4
$dir1 =
substr($key, $len-
4, 2);
if ($len-
4 <
0 ||
strlen($dir1) <
2) {
$dir2 =
substr($key, $len-
2, 2);
if ($len-
2 <
0 ||
strlen($dir2) <
2) {
$map =
$this->config->get('cachemanager_localfile');
$tmp_key =
$namespace .
"::" .
$key;
foreach ($map as $key =>
$value) {
return sprintf("%s/cache/%s/cache_%s/%s/%s", $this->backend->getTmpdir(), $dir, $this->_escape($namespace), $this->_escape($dir1), $this->_escape($dir2));
function _getCacheFile($namespace, $key)
return sprintf("%s/%s", $this->_getCacheDir($namespace, $key), $this->_escape($key));
function _escape($string)
return preg_replace('/([^0-9A-Za-z_])/e', "sprintf('%%%02X', ord('\$1'))", $string);
Documentation generated on Fri, 11 Nov 2011 04:00:05 +0900 by phpDocumentor 1.4.3