定制 arnapou/psr-cache 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

arnapou/psr-cache

最新稳定版本:v1.2.0

Composer 安装命令:

composer require arnapou/psr-cache

包简介

Library - PSR-6, PSR-16.

README 文档

README

pipeline coverage

KISS (Keep It Simple Stupid) PSR (PHP Standards Recommendations) classes.

Installation

composer require arnapou/psr-cache

packagist 👉️ arnapou/psr-cache

Example PSR-6 Cache

KISS, here we only have PSR-6 adapter of PSR-16 Simple cache.

Note that you can inject your own PSR-20 Clock Interface.

$cache = new \Arnapou\Psr\Psr6Cache\CacheItemPool(
    psr16SimpleCache: $psr16SimpleCache, 
    defaultTtl: 900, 
);
$item = $cache->getItem('my-key');
$item->set('my-value');
$item->expiresAfter(300);
$cache->save($item);

Example PSR-16 Simple Cache

There is one thing I didn't implement from the PSR : it is the PSR key characters restriction.

Because I never saw a case during the past 12 years where it was necessary.

The only restrictions implemented are technically (ex memcached).

Implementations.

use Arnapou\Psr\Psr16SimpleCache;

// For runtime, full memory
$cache = new Psr16SimpleCache\ArraySimpleCache(defaultTtl: 900);

// Flat file cache with custom serializer and PSR-20 Clock Interface
$cache = new Psr16SimpleCache\FileSimpleCache(path: '/path/of/cache', defaultTtl: 900);

// Memcached cache with custom serializer and PSR-20 Clock Interface
$cache = new Psr16SimpleCache\MemcachedSimpleCache($memcached);

// Redis cache with custom serializer and PSR-20 Clock Interface
$cache = new Psr16SimpleCache\RedisSimpleCache($redis);

// Does nothing at all
$cache = new Psr16SimpleCache\NullSimpleCache();

Decorators.

use Arnapou\Psr\Psr16SimpleCache\Decorated;

// Helps to reduce I/Os on decorated cache by keeping in memory the values already retrieved
$cache = new Decorated\RuntimeSimpleCache($decorated);

// Helps to isolate keys in "namespaces" for instance
$cache = new Decorated\PrefixSimpleCache($decorated, 'some:prefix');

// Forces the ttl to be in the range wanted to avoid silly TTLs
$cache = new Decorated\TtlRestrictedSimpleCache($decorated, ttlMin: 60, ttlMax: 3600);

// Avoid any writing in that cache
$cache = new Decorated\ReadonlySimpleCache($decorated, throwException: true);

Php versions

DateRef8.58.48.38.2
25/10/20251.2.x, main×××
24/11/20241.1.x×××
09/09/20241.0.x××

统计信息

  • 总下载量: 518
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-09