flaphl / cache
Caching abstractions pulled from Flaphl elements.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/flaphl/cache
Requires
- php: ^8.2
- flaphl/cache-contracts: ^1.0
- flaphl/deprecation-contracts: ^2.1
- psr/cache: ^1.0 || ^2.0 || ^3.0
- psr/log: ^1.0 || ^2.0 || ^3.0
Requires (Dev)
- phpunit/phpunit: ^10.0 || ^11.0
- psr/simple-cache: ^1.0 || ^3.0
Provides
- flaphl/cache-implementation: 1.0
- psr/cache-implementation: 1.0|2.0|3.0
- psr/simple-cache-implementation: 1.0|2.0
Conflicts
- flaphl/injection: <1.0
README
PSR-6 cache implementation pulled from Flaphl elements.
Installation
composer require flaphl/cache
Features
- PSR-6 Cache compliance - Full compatibility with PSR Cache interfaces
- Multiple adapters - Array, Filesystem, PHP Array, PHP Files, and Null adapters
- Tag-aware caching - Cache invalidation by tags
- Advanced expiration - TTL, DateTime, and DateInterval support
- Concurrent access control - File and memory-based locking mechanisms
- Comprehensive testing - Extensive test suite with integration tests
Basic Usage
use Flaphl\Element\Cache\Adapter\ArrayAdapter; // Create cache adapter $cache = new ArrayAdapter('my_namespace'); // Store an item $item = $cache->getItem('user.123'); $item->set(['name' => 'John Doe', 'email' => 'john@example.com']); $item->expiresAfter(3600); // 1 hour $cache->save($item); // Retrieve an item $item = $cache->getItem('user.123'); if ($item->isHit()) { $userData = $item->get(); }
Tag-Aware Caching
use Flaphl\Element\Cache\Adapter\TagAwareAdapter; $tagAwareCache = new TagAwareAdapter($cache, $tagIndexCache); // Save item with tags $item = $tagAwareCache->getItem('product.456'); $item->set(['name' => 'Widget', 'price' => 29.99]); $item->tag(['products', 'category:widgets']); $tagAwareCache->save($item); // Invalidate by tags $tagAwareCache->invalidateTags(['products']);
Available Adapters
- ArrayAdapter - In-memory storage with optional size limits
- FilesystemAdapter - File-based persistent storage
- PhpArrayAdapter - Single PHP file array storage
- PhpFilesAdapter - Multiple PHP files with opcache optimization
- NullAdapter - No-op adapter for testing/debugging
- TagAwareAdapter - Decorator adding tagging support
License
This package is licensed under the MIT License. See the LICENSE file for details.