- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
<?php
class Cache
{
var $secret;
function create($timexpire, $data, $catalog="cache/"){
$filename = $catalog.$this->cache().".cache";
$data = "$timexpire\n$data";
$fo = fopen($filename, "w");
fwrite($fo, $data);
fclose($fo);
}
function read($catalog = "cache/"){
$filename = $catalog.$this->cache().".cache";
if(file_exists($filename)){
$content = file($filename);
if(trim($content[0]) < time()){
return 0;
}
unset($content[0]);
return ltrim(implode('', $content));
}
return 0;
}
function clean($catalog = "cache/"){
if($data = glob($catalog."*")){
foreach($data as $o){
if(is_dir($o)){
$this->clean($o);
}else{
unlink($o);
}
}
}
rmdir($catalog);
}
function cache(){
$filename = $_SERVER['REQUEST_URI'];
if(isset($_POST)){
$filename .= implode('',$_POST);
}
return md5($this->secret.$filename);
}
}
?>
Мой класс для кеширования.
Писал давно.