flatphp /cache
缓存组件
v3.0.0
2022-02-02 07:16 UTC
Requires
- php: >=8.1
- flatphp/memstore: ^3.0
This package is auto-updated.
Last update: 2024-08-29 04:01:19 UTC
README
轻量级缓存组件;
相关: https://github.com/flatphp/memstore
安装
composer require "flatphp/cache"
初始化配置
use Flatphp\Memstore\Conn; use Flatphp\Cache\Cache; Conn::init(array( 'memcache' => ['host' => '127.0.0.1', 'port' => 11211] )); Cache::init(array( 'expiration' => 3600, // the default expiration, 0 forever[default] 'storage' => 'memcache', )); // -------- OR -------------------- Cache::init(array( 'expiration' => 3600, // the default expiration, 0 forever[default] 'storage' => array( 'driver' => 'redis', 'host' => 'localhost', 'port' => 6379 ) ));
用法
use Flatphp\Cache\Cache; Cache::set('test', 1, 60); echo Cache::get('test'); Cache::delete('test'); Cache::flush(); Cache::increment('test', 2); Cache::decrement('test', 2); Cache::getData('test', function(){ return 'hello'; });