if (!isset($this->data[$key]) || time() > $this->data[$key]['ttl']) { return null; } return $this->data[$key]['value']; } public function set($key, $value, $ttl = 0) { $this->data[$key] = array('value' => $value, 'ttl' => time() + $ttl); return true; } public function delete($key) { unset($this->data[$key]); } public function flush() { $this->data = array(); } } //设置要使用的缓存类型 if (class_exists('Yac')) { $adapter = new CacheHelper_Yac(); } else { if (function_exists('apc_fetch')) { $adapter = new CacheHelper_Apc(); } else { $adapter = new CacheHelper_Request(); } } CacheHelper::setAdapter($adapter);