* @since 1.0 */ class Cache extends Service { // 各个页面cache的配置 public $cacheConfig; // cache 总开关 public $enable; /** * @param $cacheKey | String , 具体的缓存名字,譬如 product category * @return boolean, 如果enable为true,则返回为true * 根据传递的$cacheKey,从配置中读取是否开启cache */ public function isEnable($cacheKey) { if ($this->enable && isset($this->cacheConfig[$cacheKey]['enable'])) { return $this->cacheConfig[$cacheKey]['enable']; } else { return false; } } /** * @param $cacheKey | String , 具体的缓存名字,譬如 product category * @return int, 如果enable为true,则返回为true * 得到$cacheKey 对应的超时时间 */ public function timeout($cacheKey) { if (isset($this->cacheConfig[$cacheKey]['timeout'])) { return $this->cacheConfig[$cacheKey]['timeout']; } else { return 0; } } /** * @param $cacheKey | String , 具体的缓存名字,譬如 product category * @return string, 如果enable为true,则返回为true */ public function disableUrlParam($cacheKey) { if (isset($this->cacheConfig[$cacheKey]['disableUrlParam'])) { return $this->cacheConfig[$cacheKey]['disableUrlParam']; } else { return ''; } } /** * @param $cacheKey | String , 具体的缓存名字,譬如 product category * @return string, 如果enable为true,则返回为true * url的参数,哪一些参数作为缓存唯一的依据,譬如p(分页的值) */ public function cacheUrlParam($cacheKey) { if (isset($this->cacheConfig[$cacheKey]['cacheUrlParam'])) { return $this->cacheConfig[$cacheKey]['cacheUrlParam']; } else { return ''; } } }