Coder Social home page Coder Social logo

think-cache's Introduction

think-cache

用于PHP缓存管理(PHP 7.1+),支持PSR-6PSR-16缓存规范。

主要特性包括:

  • 支持多缓存通道设置及切换
  • 支持缓存数据递增/递减
  • 支持门面调用
  • 内置File/Redis/Memcache/Memcached/Wincache
  • 支持缓存标签
  • 支持闭包数据
  • 支持PSR-6PSR-16缓存规范

安装

composer require topthink/think-cache

用法:

use think\facade\Cache;

// 缓存配置
Cache::config([
	'default'	=>	'file',
	'stores'	=>	[
		'file'	=>	[
			'type'   => 'File',
			// 缓存保存目录
			'path'   => './cache/',
			// 缓存前缀
			'prefix' => '',
			// 缓存有效期 0表示永久缓存
			'expire' => 0,
		],
		'redis'	=>	[
			'type'   => 'redis',
			'host'   => '127.0.0.1',
			'port'   => 6379,
			'prefix' => '',
			'expire' => 0,
		],
	],
]);
// 设置缓存
Cache::set('val','value',600);
// 判断缓存是否设置
Cache::has('val');
// 获取缓存
Cache::get('val');
// 删除缓存
Cache::delete('val');
// 清除缓存
Cache::clear();
// 读取并删除缓存
Cache::pull('val');
// 不存在则写入
Cache::remember('val',10);

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

// 使用缓存标签
Cache::tag('tag_name')->set('val','value',600);
// 删除某个标签下的缓存数据
Cache::tag('tag_name')->clear();
// 支持指定多个标签
Cache::tag(['tag1','tag2'])->set('val2','value',600);
// 删除多个标签下的缓存数据
Cache::tag(['tag1','tag2'])->clear();

// 使用多种缓存类型
$redis = Cache::store('redis');

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

更多内容可以参考 https://www.kancloud.cn/manual/thinkphp6_0/1037634

think-cache's People

Contributors

axiosleo avatar evalor avatar ichynul avatar liu21st avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

think-cache's Issues

单独安装think-cache插件后在php8.1版本中运行错误

依赖 topthink/think-container 这个没有兼容php8.0 topthink/think-container内已提交兼容php8
在使用php8.1运行时使用thinkcache 报
PHP Fatal error: During inheritance of ArrayAccess: Uncaught ErrorException: Return type of think\Container::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/wwwroot//vendor/topthink/think-container/src/Container.php:567
Stack trace:
#0 /www/wwwroot/
/vendor/topthink/think-container/src/Container.php(32): {closure}()

think-cache 1.1版本 redis没有实现断线重连

使用think-cache 1.1版本,连接操作redis 出现send of 27 bytes failed with errno 10054,read error on connection错误 网上查到是长时间没有操作redis redis服务端主动关闭了连接 希望能实现断线重连来解决这个问题

PHP8.1序列化报错

ErrorException: Opis\Closure\SerializableClosure implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /data/juxie/sword-admin/vendor/opis/closure/src/SerializableClosure.php:18

redis集群

“有需要在业务层实现读写分离、或者使用RedisCluster的需求,请使用Redisd驱动“ 请问这个驱动在哪里?

缓存文件读取异常

20200609230445

页面调起约 6~7 个ajax请求,PDOConnection 中有用到文件缓存。应该是文件缓存写入文件时 file_put_contents($filename, $data); 没加所导致的。

采用 Redis 后 Tag 功能失效

原因:
Redis->push 覆盖了 Driver->push ,这样在 TagSet->append 就会出现不一致性导致 tag 操作失效。

临时解决办法:
放弃 Redis->push 方法并将其注释掉。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.