cache = Yii::$app->cache; } /** * 设置键值对缓存数据 * @param $key * @param $value * @param int $duration * @return bool */ public function setValue($key, $value,$duration = 3600) { // TODO: Implement setValue() method. if ($this->cache) return $this->cache->set($this->prefix.$key, $value,$duration); return false; } /** * 获取键值 * @param $key * @return bool */ public function getValue($key) { if (isset($_GET['noCache']) && $_GET['noCache']=='y') return false; // TODO: Implement getValue() method. if ($this->cache) return $this->cache->get($this->prefix.$key); return false; } /** * 删除键 * @param $key * @return bool */ public function deleteValue($key) { // TODO: Implement deleteValue() method. if ($this->cache) return $this->cache->delete($this->prefix.$key); return false; } /** * 获取有效期 * @return int */ public function getDuration() { return $this->duration; } }