limoncello-php / redis-tagged-cache
Redis-based Cache with Tags implementation.
0.10.0
2019-05-28 17:45 UTC
Requires
- php: >=7.1.0
- ext-redis: *
- limoncello-php/contracts: ^0.10.0
Requires (Dev)
- mockery/mockery: ^1.0
- phpmd/phpmd: ^2.4
- phpunit/phpunit: ^7.0
- scrutinizer/ocular: ^1.4
- squizlabs/php_codesniffer: ^2.9
This package is auto-updated.
Last update: 2024-11-29 05:27:06 UTC
README
Summary
This is component for Limoncello Framework that adds storing extra information (tags) in Redis cache.
Each method works in transactional way. The methods implement
- Adding value to cache with associated string tags and TTL (time-to-live).
- Removing cached value by key and associated tags.
- Invalidation (deletion) all cached values by tag.
It is designed to be easily combined with classes that work with Redis cache. All methods could be renamed using PHP Trait Conflict Resolution and visibility changed with PHP Trait Changing Method Visibility.
Integration example
use Limoncello\RedisTaggedCache\RedisTaggedCacheTrait; use Redis; /** @var Redis $redis */ $redis = ...; $cache = new class ($redis) { use RedisTaggedCacheTrait; public function __construct(Redis $redis) { $this->setRedisInstance($redis); } }; $cache->addTaggedValue('key1', 'value1', ['author:1', 'comment:2']); $cache->addTaggedValue('key2', 'value2', ['author:1', 'comment:2']); $cache->addTaggedValue('key3', 'value3', ['author:1', 'comment:2']); // removes the first key-pair $cache->removeTaggedValue('key1'); // removes 2 remaining values $cache->invalidateTag('author:1');
Testing
$ composer test