快捷搜索:   服务器  安全  linux 安全  MYSQL  dedecms

一个强大的PHP缓存类(7)


    }
    
    //writes or reads the cache
    public function cache($key, $value=''){
        if ($value!=''){//wants to write
            if (strlen(serialize($value)) > 64 ){//write independent file it's a big result
                $this->addLog('cache function write in file key:'. $key);
                $this->put($key, $value);
            }
            else {
                $this->addLog('cache function write in APP key:'. $key);
                $this->APP($key,$value);//write in the APP cache
            }
        }
        else{//reading value
            if ( $this->APP($key)!=null ){
                $this->addLog('cache function read APP key:'. $key);
                return $this->APP($key);//returns from app cache
            }
            else {
                $this->addLog('cache function read file key:'. $key);
                return $this->get($key);//returns from file cache
            }
        }
    }
    
    //deletes a key from cache
    public function delete($name){
        if ( $this->APP($name)!=null ){//unset the APP var
            $this->addLog('unset APP key:'. $name);
            unset($this->application[md5($name)]);
            $this->application_write=true;//says that we have changes to later save the APP
        }
        elseif ( file_exists($this->fileName($name)) ){//unlink filename
            $this->addLog('unset File key:'. $name);
            unlink($this->fileName($name));         
        }
    }
    
    // Overloading for the variables and automatically cached
        public function __set($name, $value) {
            $this->cache($name, $value);
        }
    
        public function __get($name) {
            return $this->cache($name);
        }
    
        public function __isset($name) {//echo "Is '$name' set?\n"
            $this->addLog('isset key:'. $name);
            $value=$this->cache($name);
            return isset($value);
        }
    
        public function __unset($name) {//echo "Unsetting '$name'\n";
            $this->delete($name);
        }
顶(0)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论