temant / cache-manager
A flexible caching system with multiple adapters (Redis, Memcached, File).
Requires
- ext-memcached: *
- ext-redis: *
- psr/cache: ^3.0
Requires (Dev)
- mikey179/vfsstream: ^1.6
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^11.2
- symfony/var-dumper: ^7.1
This package is not auto-updated.
Last update: 2025-04-15 15:28:38 UTC
README
A flexible caching system that supports multiple adapters, including Redis, Memcached, and File-based caching. This library is PSR-6 compatible, making it easy to integrate with existing PHP applications.
Features
- Redis Cache Adapter: High-performance caching using Redis.
- Memcached Cache Adapter: Lightweight and distributed caching with Memcached.
- Single-File PHP Cache Adapter: A simple file-based cache stored in a single PHP file.
- Flexible Cache Manager: Seamlessly switch between cache adapters.
- PSR-6 Compliant: Compatible with any PSR-6-based applications.
Installation
-
Install via Composer:
composer require temant/cache-system
-
Ensure you have Redis and Memcached installed if using their respective adapters:
- For Redis:
sudo apt install redis-server
- For Memcached:
sudo apt install memcached
- For Redis:
Usage
Basic Setup
use Temant\Cache\CacheManager; use Temant\Cache\Adapter\RedisCacheAdapter; // Example using Redis adapter $redisAdapter = new RedisCacheAdapter('127.0.0.1', 6379); $cacheManager = new CacheManager($redisAdapter); // Save an item in the cache $cacheItem = $cacheManager->getItem('my_key'); $cacheItem->set('some_value'); $cacheManager->save($cacheItem); // Retrieve the item from the cache $cachedItem = $cacheManager->getItem('my_key'); if ($cachedItem->isHit()) { echo $cachedItem->get(); // Outputs 'some_value' } // Switch to another adapter dynamically $memcachedAdapter = new MemcachedCacheAdapter('127.0.0.1', 11211); $cacheManager->setAdapter($memcachedAdapter);
Running Tests
You can run the test suite with PHPUnit:
composer test
Static analysis with PHPStan:
composer phpstan
Contributing
Feel free to submit issues or pull requests. For major changes, please open an issue to discuss what you would like to change.
License
This project is licensed under the MIT License - see the LICENSE file for details.