From 673c022e715acee9ce3bad4145cbdcfae995d40a Mon Sep 17 00:00:00 2001 From: Grzegorz Surmann Date: Mon, 2 Sep 2024 20:02:41 +0200 Subject: [PATCH] some cleanup --- inc/Class.PHPCACHER.inc.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) 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; } }