cuephp / cache
一个轻量级的缓存库
0.2.0
2021-12-05 14:14 UTC
Requires
- php: ^7.3||^8.0
- psr/cache: ^1.0
- psr/simple-cache: ^1.0||^2.0
Requires (Dev)
- phpstan/phpstan: ^1.2
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: *
Suggests
- ext-memcached: use the memcached client
- ext-redis: use the phpredis client
- ext-yac: use yac cache server
Provides
- psr/cache-implementation: 1.0
- psr/simple-cache-implementation: 1.0||2.0
README
支持的存储引擎
- 内存
- 文件
- Memcached
- Redis
- Yac
安装
compose require cuephp/cache
缓存使用
use CuePhp\Cache\Engine\InMemoryEngine; use CuePhp\Cache\Config\InMemoryConfig; $config = new InMemoryConfig; $engine = new InMemoryEngine( $config ); $engine->set( 'key', 'value', 10 ); $item = $engine->get('key'); $item->getData(); // return 'value'
计数器使用
use CuePhp\Cache\Engine\InMemoryEngine; use CuePhp\Cache\Config\InMemoryConfig; $config = new InMemoryConfig; $engine = new InMemoryEngine( $config ); $incrCounter= $engine->incr( 'key' ); $value = $incrCounter->getData(); //return 1 if 'key' not exist $incrCount = $engine->incr('key', 10); $value = $incrCounter->getData(); //return 11