first final version

This commit is contained in:
Grzegorz Surmann 2024-09-02 19:57:50 +02:00
parent b0007e94ad
commit 94fd786764
2 changed files with 22 additions and 0 deletions

View File

@ -8,3 +8,4 @@ $item1="Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
Cache::put("lorem",$item1);
print_r(Cache::get("lorem"));
print "\n";

View File

@ -2,12 +2,33 @@
class PHPCACHER {
static function isCached($item) {
if ( !isset($phpcacher_ttl) ) { $phpcacher_ttl=3600; };
if ( !isset($phpcacher_path) ) { $phpcacher_path="./cache"; };
$file=md5($item);
}
static function put($item,$data) {
if ( !isset($phpcacher_path) ) { $phpcacher_path="./cache"; };
@mkdir($phpcacher_path,0755,TRUE);
$file=$phpcacher_path."/".md5($item).".data";
file_put_contents($file,serialize($data));
return TRUE;
}
static function get($item) {
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 ) {
return unserialize(file_get_contents($file));
}
}
return FALSE;
}
static function del($item) {
if ( !isset($phpcacher_path) ) { $phpcacher_path="./cache"; };
$file=$phpcacher_path."/".md5($item).".data";
@unlink($file);
return TRUE;
}
}