1 Star 1 Fork 1

iRavior / think-cache

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
thinkphp 提交于 2017-12-09 16:38 . 首次提交

think-cache

用于PHP缓存管理(PHP>5.6+)

安装

composer require topthink/think-cache

用法:

use think\Cache;

// 缓存初始化
Cache::init([
	// 驱动方式(支持file/memcache/redis/xcache/wincache/sqlite)
	'type'   => 'File',
	// 缓存保存目录
	//'path'   => './cache/',
	// 缓存前缀
	'prefix' => '',
	// 缓存有效期 0表示永久缓存
	'expire' => 0,
]);
// 设置缓存
Cache::set('val','value',600);
// 判断缓存是否设置
Cache::has('val');
// 获取缓存
Cache::get('val');
// 删除缓存
Cache::rm('val');
// 清除缓存
Cache::clear();
// 读取并删除缓存
Cache::pull('val');
// 不存在则写入
Cache::remember('val','value');

// 对于数值类型的缓存数据可以使用
// 缓存增+1
Cache::inc('val');
// 缓存增+5
Cache::inc('val',5);
// 缓存减1
Cache::dec('val');
// 缓存减5
Cache::dec('val',5);

// 使用多种缓存类型
$redis = Cache::connect([
	// 驱动方式(支持file/memcache/redis/xcache/wincache/sqlite)
	'type'   => 'redis',
        'host'       => '127.0.0.1',
        'port'       => 6379,
	// 缓存前缀
	'prefix' => '',
	// 缓存有效期 0表示永久缓存
	'expire' => 0,
]);

$redis->set('var','value',600);
$redis->get('var');

// 或者使用
$redis->val = 'value';
echo $redis->val;
PHP
1
https://gitee.com/ravior/think-cache.git
git@gitee.com:ravior/think-cache.git
ravior
think-cache
think-cache
master

搜索帮助