Skip to content
RT Softs

Laravel caching with Redis: tags, TTLs and stampedes

Cache the expensive read, invalidate it deliberately, and never cache models — the pitfalls are predictable once you name them.

A Admin
September 16, 2026 2 min read Updated Nov 19, 2026

Caching is easy to add and easy to get subtly wrong. The three failures we see most are stale data nobody invalidates, a cache stampede when a key expires, and a cached object that cannot be unserialised.

Cache data, not models

Laravel can serialise Eloquent models, but the database cache store may be configured to refuse class unserialisation, and a cached model can be stale in ways that are hard to trace. Cache arrays of scalars and rehydrate, or cache the rendered fragment.

Choose the invalidation strategy first

Either a short TTL with tolerable staleness, or explicit invalidation on write. Mixing the two without a plan produces "sometimes wrong" bugs. For content that editors change, tag the cache and flush the tag in the model event.

Avoid the stampede

When a popular key expires, every concurrent request recomputes it at once. Use the lock helper or cache::flexible-style early expiration so one request refreshes while others serve the stale value. On a busy page this is the difference between a blip and an outage.

Scope keys properly

Include the tenant, locale and any filter in the key. A key like "posts" will serve one user's filtered page to another. Prefix by environment too, so staging and production can share a Redis instance without crossing streams.

Frequently asked questions

Redis or database cache?

Redis for anything with real traffic; the database store is convenient for a small site and adds load to the database you are trying to protect.

How long should a TTL be?

As long as the data can be stale without hurting someone. A homepage section can be an hour; a price should be minutes or explicitly invalidated.

More on this topic: Performance & SEO articles.

A

Admin

Related articles