vakata/cache

一组具有通用接口的缓存类

3.0.2 2024-03-26 15:23 UTC

This package is auto-updated.

Last update: 2024-08-26 16:15:51 UTC


README

Latest Version on Packagist Software License Build Status Code Climate Tests Coverage

一组具有通用接口的缓存类(目前支持文件缓存和Memcached)。

安装

通过Composer

$ composer require vakata/cache

使用方法

// create an instance (with file based cache)
// caches will be stored in the dir specified by the first argument
$cache = new \vakata\cache\Filecache(__DIR__ . '/cache'); 
// to use Memcached instead simply create a memcached instance:
// $cache = new \vakata\cache\Memcache(); // by default connects to 127.0.0.1

// simple get / set
$cache->set('key', 'value'); // key is stored and "value" is returned
$cache->get('key'); // "value"

// using prepare ensures that a single client updates the cache at any given moment
$cache->prepare('long-running-operation');
$data = long_running_operation();
$cache->set('long-running-operation', $data);

// there is a special getSet method which gets the current key value and if it does not exist - invokes a callable, stores the result and returns it:
$cache->getSet('some-key', function () {
    return some_long_running_operation();
});

更多请阅读API文档

测试

$ composer test

贡献

有关详细信息,请参阅贡献指南

安全

如果您发现任何安全相关问题,请通过github@vakata.com发送电子邮件,而不是使用问题跟踪器。

鸣谢

许可

MIT许可(MIT)。有关更多信息,请参阅许可文件