chilimatic / cache-component
chilimatic框架中的缓存组件
2.1.2
2018-06-10 16:53 UTC
Requires
- php: >=7.1
- chilimatic/interfaces-component: 2.*
Requires (Dev)
- phpunit/phpunit: 6.5.*
This package is auto-updated.
Last update: 2024-09-09 13:49:57 UTC
README
目前有3个适配器
Memcached、Apcu和Memory
它还附带了一个单例包装器,但您不必使用它。
$cache = Cache::getInstance(['type' => chilimatic\lib\Cache\Engine\Adapter\Memory::class]);
如果您想使用工厂
$cache = CacheFactory::make(chilimatic\lib\Cache\Engine\Adapter\Memory::class);
当然,您可以直接访问它们
$cache = new chilimatic\lib\Cache\Engine\Adapter\Memory();
您可以传入数组或stdClass,无论如何都会将其转换为数组(嵌套的也可以)
$cache = new chilimatic\lib\Cache\Engine\Adapter\Memcached([ 'server_list' => [[ 'host' => '127.0.0.1', 'port' => 11211, 'weight' => 1 ]], 'options' => [ // the options are per instance not per connection! Memcached::OPT_HASH => Memcached::HASH_MURMUR ] ]);
有关可能的选项的更多信息 https://php.ac.cn/manual/en/memcached.constants.php
$cache = new chilimatic\lib\Cache\Engine\Adapter\APCU();
这个库的一个好处是,它实际上允许您看到理论上存储在缓存中的内容
$cache = chilimatic\lib\Cache\Engine\Adapter\Memory(); var_dump($cache->listEntries());
它有1个依赖项,即chilimatic接口。
如果您想了解事物的工作原理,我建议查看测试用例 :)