diff --git a/inc/Class.PHPCACHER.inc.php b/inc/Class.PHPCACHER.inc.php index a2d1311..f9afaab 100644 --- a/inc/Class.PHPCACHER.inc.php +++ b/inc/Class.PHPCACHER.inc.php @@ -4,7 +4,18 @@ class PHPCACHER { static function isCached($item) { if ( !isset($phpcacher_ttl) ) { $phpcacher_ttl=3600; }; if ( !isset($phpcacher_path) ) { $phpcacher_path="./cache"; }; - $file=md5($item); + $file=$phpcacher_path."/".md5($item).".data"; + if ( file_exists($file) ) { + return TRUE; + } + } + static function isValid($item) { + if ( !isset($phpcacher_ttl) ) { $phpcacher_ttl=3600; }; + if ( !isset($phpcacher_path) ) { $phpcacher_path="./cache"; }; + $file=$phpcacher_path."/".md5($item).".data"; + if ( filemtime($file) > time()-$phpcacher_ttl ) { + return TRUE; + } } static function put($item,$data) { if ( !isset($phpcacher_path) ) { $phpcacher_path="./cache"; }; @@ -17,8 +28,8 @@ class PHPCACHER { if ( !isset($phpcacher_ttl) ) { $phpcacher_ttl=3600; }; if ( !isset($phpcacher_path) ) { $phpcacher_path="./cache"; }; $file=$phpcacher_path."/".md5($item).".data"; - if ( file_exists($file) ) { - if ( filemtime($file) > time()-$phpcacher_ttl ) { + if ( self::isCached($item) ) { + if ( self::isValid($item) ) { return unserialize(file_get_contents($file)); } } @@ -27,7 +38,9 @@ class PHPCACHER { static function del($item) { if ( !isset($phpcacher_path) ) { $phpcacher_path="./cache"; }; $file=$phpcacher_path."/".md5($item).".data"; - @unlink($file); + if ( self::isCached($item) ) { + @unlink($file); + } return TRUE; } }