stepanrodionov/php-apcu-cache

这是一个使用php-apcu模块的PSR-16兼容缓存库

2.0.3 2019-01-18 11:06 UTC

This package is auto-updated.

Last update: 2024-09-18 23:31:40 UTC


README

Latest Stable Version Latest Unstable Version License Codacy Badge

php-apcu-cache (PSR-16)

这是一个使用php-apcu模块的PSR-16兼容缓存库。它提供了一个ApcuCacheStorage类,该类实现了Psr\SimpleCache\CacheInterface接口,可以在需要PHP缓存的代码中任何地方使用。

关于apcu

php-apcu提供内存缓存,用于在请求之间存储变量。您可以在此页面上了解更多信息。

使用方法

您应该创建ApcuCacheStorage的实例,并在获取其功能访问权时

$cache = new SR\Cache\ApcuCacheStorage();

//  store variable with ttl
$success = $cache->set('key', $variable, 3600);

//  get variable
$variable = $cache->get('key');

//  'key' will be overwritten
$cache->set('key', $anotherVar, 3600);

//  deleting one cached variable and all of them
$cache->delete('key');
$cache->clear();

// dealing with multiple data
$cache->getMultiple([
    'key', 
    'key1',
]);
$cache->setMultiple([
    'key' => 'value',
    'key1' => 'value1',
]);
$cache->deleteMultiple([
    'key', 
    'key1',
]);

//  check if variable exists
$isVarCached = $cache->has('key');

测试

运行composer test

许可证

此组件遵循MIT许可证。请参阅LICENSE文件中的完整许可证。