spatie/laravel-responsecache
Cache full Laravel responses to speed up your app. Automatically caches successful text-based GET requests (HTML/JSON), with easy middleware per route, configurable lifetimes, and optional stale-while-revalidate “grace” caching to refresh in the background.
lifetime: hours(1), grace: minutes(5)) to balance freshness and performance.#[Cache] attributes for granular control (e.g., /users/{id} with 5-minute TTL)./posts?limit=10) with short TTLs or tag-based invalidation.Adopt if:
ResponseCache::clear()) or tag-based (e.g., CacheResponse::for()->withTags(['posts'])).Look elsewhere if:
@cache) or Edge Side Includes (ESI).For Executives:
"This package lets us cut server costs by 30–50% for read-heavy routes by caching full HTTP responses—like serving a pre-rendered dashboard instead of reprocessing data every time. For example, a marketing site with 1M monthly visitors could reduce backend load by ~70% for static pages, delaying cloud spend growth. It’s a no-code, low-risk way to improve performance without hiring devs or buying new infrastructure. We’ll start with high-traffic routes (e.g., /docs, /pricing) and expand to APIs later. ROI is immediate: faster pages = higher conversion, and lower costs = better margins."
For Engineering:
*"Spatie’s laravel-responsecache gives us a batteries-included way to cache entire responses (HTML/JSON) at the middleware level, with flexible TTLs and tag-based invalidation. Key benefits:
CacheResponse::for(minutes(10)).FlexibleCacheResponse).#[Cache] attributes to controllers for granular control.X-Response-Cache: HIT).
Tradeoff: Not suitable for real-time data or complex POST workflows, but perfect for static or semi-static content. Let’s pilot it on /posts and /dashboard first to measure impact."*For Developers:
*"This replaces our hacky Cache::remember() calls with a clean, middleware-based solution. Highlights:
Route::middleware(CacheResponse::for(hours(1)))->get('/...').FlexibleCacheResponse).ResponseCache::clear(['posts'])).?sort=asc and ?sort=desc get separate caches./docs and /pricing—low risk, high reward."How can I help you explore Laravel packages today?