/** * 设置一个缓存值 * 如果数据有回滚的话,那么我们把cache删除掉,下次不再从缓存读 * @author 欧远宁 * @param string $id 缓存的key * @param any $data 需要缓存的内容 * @param int $lifeTime 缓存时间,单位为秒,默认0 * @param bool $force 是否强制更新,强制更新的缓存不回滚 */ public function set($id, $data, $lifeTime = 0, $force = false) { if (key_exists($id, $this->del_list)) { unset($this->del_list[$id]); } if ($force) { //强制更新 if (key_exists($id, $this->buf_list)) { unset($this->buf_list[$id]); } $this->open(); $this->mem_cls->set($id, $data, $lifeTime); } else { $this->buf_list[$id] = array($data, $lifeTime); } }
/** * 根据筛选条件获取所有的id列表 * @author 欧远宁 * @param array $filter 筛选条件 * @param array $page 分页信息 * @param array $order 排序信息 * @return array 结果集 */ private function get_rec($filter, $page = null, $order = null) { $rec = array(); if ($this->schema['cache'] > -1) { //每个表对应查询缓存的流水好,当该表的数据变更后,该流水号会递增,以便使其查询缓存失效 $flow = $this->cache->get('qc.' . $this->mdl . '.' . $this->tbl, '0'); $flow = $flow == '' ? '0' : $flow; $tid = 'gqc.' . md5($this->mdl . $this->tbl . serialize(array($filter, $page, $order)) . $flow); $rec = $this->cache->get($tid); if ($rec == '') { //未缓存命中 $rec = $this->query($filter, $page, $order); $this->cache->set($tid, $rec); } } else { $rec = $this->query($filter, $page, $order); } return $rec; }