Looking to hire Laravel developers? Try LaraJobs

laravel-redis-cache maintained by jishan-shk

Description
Laravel Redis cache store with pattern/tag based invalidation and model observer helpers.
Author
Last update
2026/10/05 09:27 (dev-main)
License
Links
Downloads
2

Comments
comments powered by Disqus

jishan-shk/laravel-redis-cache

Laravel Redis cache store with pattern/tag based invalidation, plus a trait for clearing cache from model observers.

Installation

composer require jishan-shk/laravel-redis-cache

The service provider is auto-discovered. It swaps Laravel's cache manager so the redis driver uses a store that supports keys() and forgetByPattern(). Set CACHE_STORE=redis (or CACHE_DRIVER=redis on Laravel 10).

Usage

Tagged list cache

use JishanShk\RedisCache\Services\ListCacheService;

$events = app(ListCacheService::class)->remember('events:list', ['events'], 3600, fn () => Event::all());

// Forget every key tagged "events"
clearCacheByPattern('events');
invalidateListCacheTags(['events', 'calendar']);

Clearing cache from an observer

use JishanShk\RedisCache\Traits\ClearsModelCache;

class EventObserver
{
    use ClearsModelCache;

    protected $cacheTags = ['events'];
}

The tags are cleared on saved and deleted. See stubs/EventObserver.php.

Suppressing invalidation

use JishanShk\RedisCache\Support\CacheInvalidationSuppressor;

CacheInvalidationSuppressor::suppress(function () {
    // bulk writes; observers won't clear cache here
});
clearCacheByPattern('events'); // clear once afterwards

Flush by raw pattern

use JishanShk\RedisCache\Cache\FlushRedis;

new FlushRedis('events:');