chillerlan/php-cache

5.1.0 2024-02-25 16:01 UTC

This package is auto-updated.

Last update: 2024-09-07 00:37:43 UTC


README

PHP 8.1+ 的 psr/simple-cache 实现。

PHP Version Support version license Coverage Codacy Packagist downloads
Continuous Integration

功能

要求

文档

使用 composer 安装

您只需克隆仓库并在根目录中运行 composer install。如果您想在其他地方使用它,只需将以下内容添加到您的 composer.json

(注意:将 dev-main 替换为版本约束,例如 ^4.1 - 请参阅发布版本以获取有效版本)

{
	"require": {
		"php": "^8.1",
		"chillerlan/php-cache": "dev-main"
	}
}

通过终端安装:composer require chillerlan/php-cache

成功!

用法

只需像这样调用带有所需 CacheInterface 的缓存实例

// Redis
$redis = new Redis;
$redis->pconnect('127.0.0.1', 6379);

$cache = new RedisCache($redis);

// Memcached
$memcached = new Memcached('myCacheInstance');
$memcached->addServer('localhost', 11211);

$cache = new MemcachedCache($memcached);

// APCU
$cache = new APCUCache;

// File
$cache = new FileCache(new CacheOptions(['cacheFilestorage' => __DIR__.'/../.cache']));

// Session
$cache = new SessionCache(new CacheOptions(['cacheSessionkey' => '_my_session_cache']));

// Memory
$cache = new MemoryCache;

方法

查看:Psr\SimpleCache\CacheInterface

$cache->get(string $key, $default = null); // -> mixed
$cache->set(string $key, $value, int $ttl = null):bool
$cache->delete(string $key):bool
$cache->has(string $key):bool
$cache->clear():bool
$cache->getMultiple(array $keys, $default = null):array // -> mixed[]
$cache->setMultiple(array $values, int $ttl = null):bool
$cache->deleteMultiple(array $keys):bool

免责声明!

我不对熔化的内存模块、膨胀的硬盘、自诱导的DoS、破碎的屏幕等问题负责。请在自己的风险下使用!🙈