byjg / cache-engine
A multi-purpose cache engine PSR-6 and PSR-16 implementation with several drivers.
Fund package maintenance!
byjg
Installs: 61 842
Dependents: 9
Suggesters: 2
Security: 0
Stars: 10
Watchers: 1
Forks: 4
Open Issues: 0
pkg:composer/byjg/cache-engine
Requires
- php: >=8.1 <8.4
- psr/cache: ^1.0|^2.0|^3.0
- psr/container: ^1.0|^1.1|^2.0
- psr/log: ^1.0|^1.1|^2.0
- psr/simple-cache: ^1.0|^2.0
Requires (Dev)
- phpunit/phpunit: ^9.6
- vimeo/psalm: ^5.9
Suggests
- ext-memcached: *
- ext-redis: *
- ext-shmop: *
Provides
README
PHP Cache Engine
A powerful, versatile cache implementation providing both PSR-6 and PSR-16 interfaces with support for multiple storage drivers.
Key Features
- PSR-16 Simple Cache interface - Simple, straightforward caching API
- PSR-6 Cache Pool interface - More verbose caching with fine-grained control
- Multiple storage backends - Choose from memory, file system, Redis, Memcached and more
- Atomic operations - Support for increment, decrement and add operations in compatible engines
- Garbage collection - Automatic cleanup of expired items
- PSR-11 container support - Retrieve cache keys via dependency container
- Logging capabilities - PSR-3 compatible logging of cache operations
Quick Start
composer require "byjg/cache-engine"
// PSR-16 Simple Cache $cache = new \ByJG\Cache\Psr16\FileSystemCacheEngine(); $cache->set('key', 'value', 3600); // Cache for 1 hour $value = $cache->get('key'); // PSR-6 Cache Pool $pool = \ByJG\Cache\Factory::createFilePool(); $item = $pool->getItem('key'); if (!$item->isHit()) { $item->set('value'); $item->expiresAfter(3600); $pool->save($item); } $value = $item->get();
Documentation
Getting Started
Available Cache Engines
| Engine | Description |
|---|---|
| NoCacheEngine | No-op engine for disabling cache without code changes |
| ArrayCacheEngine | In-memory array cache (non-persistent between requests) |
| FileSystemCacheEngine | File system based caching |
| MemcachedEngine | Memcached distributed caching |
| RedisCacheEngine | Redis-based caching |
| SessionCacheEngine | PHP session-based caching |
| TmpfsCacheEngine | Tmpfs-based caching |
| ShmopCacheEngine | Shared memory caching (deprecated) |
| KeyValueCacheEngine | S3-Like or CloudflareKV storage (separate package) |
Advanced Features
Running Unit Tests
vendor/bin/phpunit --stderr
Note: The --stderr parameter is required for SessionCacheEngine tests to run properly.
Dependencies
flowchart TD
byjg/cache-engine --> psr/cache
byjg/cache-engine --> psr/log
byjg/cache-engine --> psr/simple-cache
byjg/cache-engine --> psr/container
Loading