first final version
This commit is contained in:
parent
b0007e94ad
commit
94fd786764
1
demo.php
1
demo.php
@ -8,3 +8,4 @@ $item1="Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
|
|||||||
Cache::put("lorem",$item1);
|
Cache::put("lorem",$item1);
|
||||||
|
|
||||||
print_r(Cache::get("lorem"));
|
print_r(Cache::get("lorem"));
|
||||||
|
print "\n";
|
||||||
|
@ -2,12 +2,33 @@
|
|||||||
|
|
||||||
class PHPCACHER {
|
class PHPCACHER {
|
||||||
static function isCached($item) {
|
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) {
|
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) {
|
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) {
|
static function del($item) {
|
||||||
|
if ( !isset($phpcacher_path) ) { $phpcacher_path="./cache"; };
|
||||||
|
$file=$phpcacher_path."/".md5($item).".data";
|
||||||
|
@unlink($file);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user