path = $config['server'].'/'; if($config['server']) { $this->enable = is_dir(DISCUZ_ROOT.$this->path); if(!$this->enable) { dmkdir(DISCUZ_ROOT.$this->path); $this->enable = is_dir(DISCUZ_ROOT.$this->path); } } else { $this->enable = false; } } private function cachefile($key) { return str_replace('_', '/', $key).'/'.$key; } public function get($key) { $file = DISCUZ_ROOT.$this->path.$this->cachefile($key).'.php'; if(!file_exists($file)) { return false; } $data = null; @include $file; if($data !== null) { if($data['exp'] && $data['exp'] < TIMESTAMP) { return false; } else { return $data['data']; } } else { return false; } } public function set($key, $value, $ttl = 0) { $file = DISCUZ_ROOT.$this->path.$this->cachefile($key).'.php'; dmkdir(dirname($file)); $data = array( 'exp' => $ttl ? TIMESTAMP + $ttl : 0, 'data' => $value, ); file_put_contents($file, "path.$this->cachefile($key)); } private function dir_clear($dir) { if($directory = @dir($dir)) { while($entry = $directory->read()) { $filename = $dir.'/'.$entry; if($entry != '.' && $entry != '..') { if(is_file($filename)) { @unlink($filename); } else { $this->dir_clear($filename); @rmdir($filename); } } } $directory->close(); } } public function clear() { return $this->dir_clear(DISCUZ_ROOT.$this->path); } public function inc($key, $step = 1) { $old = $this->get($key); if (!$old) { return false; } return $this->set($key, $old + $step); } public function dec($key, $step = 1) { $old = $this->get($key); if (!$old) { return false; } return $this->set($key, $old - $step); } }