some cleanup

This commit is contained in:
Grzegorz Surmann 2024-09-02 20:02:41 +02:00
parent 94fd786764
commit 673c022e71

View File

@ -4,7 +4,18 @@ class PHPCACHER {
static function isCached($item) { static function isCached($item) {
if ( !isset($phpcacher_ttl) ) { $phpcacher_ttl=3600; }; if ( !isset($phpcacher_ttl) ) { $phpcacher_ttl=3600; };
if ( !isset($phpcacher_path) ) { $phpcacher_path="./cache"; }; 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) { static function put($item,$data) {
if ( !isset($phpcacher_path) ) { $phpcacher_path="./cache"; }; if ( !isset($phpcacher_path) ) { $phpcacher_path="./cache"; };
@ -17,8 +28,8 @@ class PHPCACHER {
if ( !isset($phpcacher_ttl) ) { $phpcacher_ttl=3600; }; if ( !isset($phpcacher_ttl) ) { $phpcacher_ttl=3600; };
if ( !isset($phpcacher_path) ) { $phpcacher_path="./cache"; }; if ( !isset($phpcacher_path) ) { $phpcacher_path="./cache"; };
$file=$phpcacher_path."/".md5($item).".data"; $file=$phpcacher_path."/".md5($item).".data";
if ( file_exists($file) ) { if ( self::isCached($item) ) {
if ( filemtime($file) > time()-$phpcacher_ttl ) { if ( self::isValid($item) ) {
return unserialize(file_get_contents($file)); return unserialize(file_get_contents($file));
} }
} }
@ -27,7 +38,9 @@ class PHPCACHER {
static function del($item) { static function del($item) {
if ( !isset($phpcacher_path) ) { $phpcacher_path="./cache"; }; if ( !isset($phpcacher_path) ) { $phpcacher_path="./cache"; };
$file=$phpcacher_path."/".md5($item).".data"; $file=$phpcacher_path."/".md5($item).".data";
if ( self::isCached($item) ) {
@unlink($file); @unlink($file);
}
return TRUE; return TRUE;
} }
} }