Search by

sm-me / laravel-redis-model-cache

Optimized Redis model and hash-set caching service for Laravel Eloquent.

Maintainers

Package info

github.com/sm-me-dev/laravel-redis-model-cache

pkg:composer/sm-me/laravel-redis-model-cache

Transparency log

Statistics

Installs: 19

Dependents: 0

Suggesters: 0

Stars: 3

Open Issues: 0

v3.0.0 2026-09-01 15:50 UTC

README

Deterministic Redis caching for high-read Eloquent tables whose small set of filter fields is known up front. It replaces repeated database reads with indexed Redis lookups; it is not a general-purpose Eloquent query cache.

It does not support !=, LIKE, arbitrary WHERE clauses, orderBy/groupBy/join, or all(). See the complete query limitations table.

Latest Version PHP Version License

What this does not do automatically

Use it when a model is read frequently, its common filters can be declared as indexes, and predictable Redis-backed reads are worth the synchronous cache maintenance on writes.

Do not use it for ad-hoc reporting queries, full-table scans, joins, or query patterns that change constantly. The cache does not automatically turn arbitrary Eloquent queries into Redis queries.

Performance model

Model cache writes are synchronous by default. A save() or delete() on a model using HasRedisModelCache updates Redis during the model event and adds Redis latency to the request. See the write-path details.

60-second quick start

composer require sm-me/laravel-redis-model-cache
use Illuminate\Database\Eloquent\Model;
use SMDev\RedisModelCache\Concerns\HasRedisModelCache;

class User extends Model
{
    use HasRedisModelCache;

    protected static function redisModelCacheConfig(): array
    {
        return ['indexes' => ['status']];
    }
}

$activeUsers = app(\SMDev\RedisModelCache\RedisModelService::class, [
    'model_class' => User::class,
    'indexes' => ['status'],
])->where(['status' => 'active']);

The trait keeps cached models and indexes synchronized on saved, deleted, and forceDeleted events. The example uses one indexed where() lookup; add only fields your application queries regularly.

Full documentation

Requirements

  • PHP 8.3 or 8.4
  • Laravel 11, 12, or 13
  • Redis with phpredis or Predis

License and support

MIT. See LICENSE, CONTRIBUTING.md, and SECURITY.md.