一个强大的PHP缓存类(9)
return null;//was expired you need to create new
}
}
//returns the filename for the cache
private function fileName($key){
return $this->cache_path.md5($key);
}
//////////END Cache for files individually///////////////////
//////////Cache for APP variables///////////////////
//load variables from the file
private function APP_start ($app_file='application'){
$this->application_file=$app_file;
if (file_exists($this->cache_path.$this->application_file)){ // if data file exists, load the cached variables
//erase the cache every X minutes
$app_time=filemtime($this->cache_path.$this->application_file)+$this->cache_expire;
if (time()>$app_time){
$this->addLog('deleting APP file: '.$this->cache_path.$this->application_file);
unlink ($this->cache_path.$this->application_file);//erase the cache
}
else{//not expired
$filesize=filesize($this->cache_path.$this->application_file);
if ($filesize>0){
$file = fopen($this->cache_path.$this->application_file, 'r');// read data file
if ($file){
$this->addLog('reading APP file: '.$this->cache_path.$this->application_file);
$data = fread($file, $filesize);
fclose($file);
$this->application = unserialize($data);// build application variables from data file
}//en if file could open
}//end if file size
}
}
else {//if the file does not exist we create it
$this->addLog('creating APP file: '.$this->cache_path.$this->application_file);
顶(0)
踩(0)
- 最新评论
