infocyph/cachelayer
Composer 安装命令:
composer require infocyph/cachelayer
包简介
PSR-6/PSR-16 cache layer with local, distributed, and cloud adapters.
关键字:
README 文档
README
CacheLayer is a standalone cache toolkit for modern PHP applications. It provides a unified API over PSR-6 and PSR-16 with local, distributed, and cloud adapters.
Project Background
CacheLayer was separated from the existing Intermix project to improve package visibility, maintenance focus, and faster feature enrichment for caching.
Features
- Unified
Cachefacade implementing PSR-6, PSR-16,ArrayAccess, andCountable - Adapter support for APCu, File, PHP Files, Memcached, Redis, Valkey, Redis Cluster, PDO (SQLite default), Shared Memory, MongoDB, and ScyllaDB
- Tiered cache composition via
Cache::tiered()(L1/L2/... descriptors or pool instances) - Tagged invalidation with versioned tags:
setTagged(),invalidateTag(),invalidateTags() - Stampede-safe
remember()with pluggable lock providers - Per-adapter metrics counters and export hooks
- Payload compression controls
- Value serializer helpers for closures/resources
- Memoization helpers:
memoize(),remember(),once()
Requirements
- PHP 8.3+
- Composer
Optional extensions/packages depend on adapter choice:
ext-apcuext-redisext-memcachedext-pdo+ driver (pdo_sqlite,pdo_pgsql,pdo_mysql, ...)ext-sysvshmmongodb/mongodbext-cassandra
Installation
composer require infocyph/cachelayer
Usage
use Infocyph\CacheLayer\Cache\Cache; $cache = Cache::pdo('app'); // defaults to sqlite file under sys temp cachelayer/pdo $cache->setTagged('user:1', ['name' => 'Ada'], ['users'], 300); $user = $cache->remember('user:1', function ($item) { $item->expiresAfter(300); return ['name' => 'Ada']; }, tags: ['users']); $cache->invalidateTag('users'); $metrics = $cache->exportMetrics();
Tiered Flow (L1 -> L2 -> DB)
use Infocyph\CacheLayer\Cache\Cache; $cache = Cache::tiered([ ['driver' => 'apcu', 'namespace' => 'app'], // L1 ['driver' => 'valkey', 'namespace' => 'app', 'dsn' => 'valkey://127.0.0.1:6379'], // L2 ], writeToL1: false); // optional L1 write-through $value = $cache->remember('user:42', function ($item) use ($pdo) { $item->expiresAfter(300); $stmt = $pdo->prepare('SELECT payload FROM users_cache_source WHERE id = ?'); $stmt->execute([42]); return $stmt->fetchColumn(); });
Request flow:
- check APCu (L1)
- check Redis/Valkey (L2)
- query DB on miss
- write L2
- optionally write L1 (controlled by
writeToL1)
Security Hardening
CacheLayer includes optional payload/serialization hardening controls:
$cache ->configurePayloadSecurity( integrityKey: 'replace-with-strong-secret', maxPayloadBytes: 8_388_608, ) ->configureSerializationSecurity( allowClosurePayloads: false, allowObjectPayloads: false, );
You can also set:
CACHELAYER_PAYLOAD_INTEGRITY_KEYCACHELAYER_MAX_PAYLOAD_BYTES
Testing
composer test:code
Or run the full test pipeline:
composer test:all
Security
Protected by PHPForge — an automated quality and security gate for PHP projects.
Made with ❤️ for the PHP communityMIT Licensed
Documentation • Security • Code of Conduct • Contributing • Report | Request | Suggest
统计信息
- 总下载量: 891
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 4
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-12