/** * 清除配置缓存 */ public static function clear() { \think\Cache::rm('db_config_cache_data'); }
/** * 缓存管理 * @param mixed $name 缓存名称,如果为数组表示进行缓存设置 * @param mixed $value 缓存值 * @param mixed $options 缓存参数 * @param string $tag 缓存标签 * @return mixed */ function cache($name, $value = '', $options = null, $tag = null) { if (is_array($options)) { // 缓存操作的同时初始化 Cache::connect($options); } elseif (is_array($name)) { // 缓存初始化 return Cache::connect($name); } if ('' === $value) { // 获取缓存 return 0 === strpos($name, '?') ? Cache::has(substr($name, 1)) : Cache::get($name); } elseif (is_null($value)) { // 删除缓存 return Cache::rm($name); } else { // 缓存数据 if (is_array($options)) { $expire = isset($options['expire']) ? $options['expire'] : null; //修复查询缓存无法设置过期时间 } else { $expire = is_numeric($options) ? $options : null; //默认快捷缓存设置过期时间 } if (is_null($tag)) { return Cache::set($name, $value, $expire); } else { return Cache::tag($tag)->set($name, $value, $expire); } } }
/** * 缓存管理 * @param mixed $name 缓存名称,如果为数组表示进行缓存设置 * @param mixed $value 缓存值 * @param mixed $options 缓存参数 * @return mixed */ function S($name, $value = '', $options = null) { if (is_array($options)) { // 缓存操作的同时初始化 \think\Cache::connect($options); } elseif (is_array($name)) { // 缓存初始化 return \think\Cache::connect($name); } if ('' === $value) { // 获取缓存 return \think\Cache::get($name); } elseif (is_null($value)) { // 删除缓存 return \think\Cache::rm($name); } else { // 缓存数据 if (is_array($options)) { $expire = isset($options['expire']) ? $options['expire'] : null; //修复查询缓存无法设置过期时间 } else { $expire = is_numeric($options) ? $options : null; //默认快捷缓存设置过期时间 } return \think\Cache::set($name, $value, $expire); } }
/** * 删除记录 * @access public * @param mixed $data 表达式 true 表示强制删除 * @return int * @throws Exception * @throws PDOException */ public function delete($data = null) { // 分析查询表达式 $options = $this->parseExpress(); if (isset($options['cache']) && is_string($options['cache'])) { $key = $options['cache']; } if (!is_null($data) && true !== $data) { if (!isset($key) && !is_array($data)) { // 缓存标识 $key = 'think:' . $options['table'] . '|' . $data; } // AR模式分析主键条件 $this->parsePkWhere($data, $options); } if (true !== $data && empty($options['where'])) { // 如果条件为空 不进行删除操作 除非设置 1=1 throw new Exception('delete without condition'); } // 生成删除SQL语句 $sql = $this->builder()->delete($options); // 获取参数绑定 $bind = $this->getBind(); if ($options['fetch_sql']) { // 获取实际执行的SQL语句 return $this->connection->getRealSql($sql, $bind); } // 检测缓存 if (isset($key) && Cache::get($key)) { // 删除缓存 Cache::rm($key); } // 执行操作 return $this->execute($sql, $bind); }
public static function clearAliasCache() { Cache::rm('think_route_map'); }
public function testStaticCall() { $this->assertTrue(Cache::set('a', 1)); $this->assertEquals(1, Cache::get('a')); $this->assertEquals(2, Cache::inc('a')); $this->assertEquals(4, Cache::inc('a', 2)); $this->assertEquals(4, Cache::get('a')); $this->assertEquals(3, Cache::dec('a')); $this->assertEquals(1, Cache::dec('a', 2)); $this->assertEquals(1, Cache::get('a')); $this->assertNotNull(Cache::rm('a')); $this->assertNotNull(Cache::clear()); }
public function testStaticCall() { $this->assertTrue(Cache::set('a', 'a')); $this->assertEquals('a', Cache::get('a')); $this->assertNotNull(Cache::rm('a')); }
/** * 延时更新检查 返回false表示需要延时 * 否则返回实际写入的数值 * @access public * @param string $guid 写入标识 * @param integer $step 写入步进值 * @param integer $lazyTime 延时时间(s) * @return false|integer */ protected function lazyWrite($guid, $step, $lazyTime) { if (false !== ($value = Cache::get($guid))) { // 存在缓存写入数据 if (NOW_TIME > Cache::get($guid . '_time') + $lazyTime) { // 延时更新时间到了,删除缓存数据 并实际写入数据库 Cache::rm($guid); Cache::rm($guid . '_time'); return $value + $step; } else { // 追加数据到缓存 Cache::set($guid, $value + $step); return false; } } else { // 没有缓存数据 Cache::set($guid, $step); // 计时开始 Cache::set($guid . '_time', NOW_TIME); return false; } }