Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Responsecache Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Performance Optimization: Accelerate read-heavy APIs and web apps by reducing backend processing time for static or semi-static responses (e.g., dashboards, documentation, marketing pages). Directly addresses latency in high-traffic routes.
  • Cost Efficiency: Reduces server load and cloud compute costs by offloading repeated requests to cache storage (e.g., Redis, database). Justifies investment for SaaS products with tiered pricing or high-scale public APIs.
  • Build vs. Buy: Avoid reinventing caching logic (e.g., custom middleware, Varnish/Nginx integration) when Laravel-native solutions suffice. Lowers dev ops overhead for teams already using Spatie’s ecosystem.
  • Roadmap Prioritization:
    • Phase 1: Implement for static content (e.g., blogs, legal pages) with long cache lifetimes (weeks).
    • Phase 2: Adopt flexible caching for dashboards (e.g., lifetime: hours(1), grace: minutes(5)) to balance freshness and performance.
    • Phase 3: Extend to APIs with #[Cache] attributes for granular control (e.g., /users/{id} with 5-minute TTL).
  • Use Cases:
    • Public-Facing Apps: Reduce origin server load for marketing sites, documentation, or e-commerce product pages.
    • Internal Tools: Cache admin dashboards or analytics reports where staleness is tolerable.
    • APIs: Optimize read-heavy endpoints (e.g., /posts?limit=10) with short TTLs or tag-based invalidation.
    • A/B Testing: Cache variant responses to avoid reprocessing logic for the same user segment.

When to Consider This Package

Adopt if:

  • Your Laravel app serves repeated GET requests with identical responses (e.g., HTML, JSON, CSV).
  • You’re using Laravel 11+ and PHP 8.4+ (or plan to upgrade soon).
  • Cache invalidation can be manual (e.g., via ResponseCache::clear()) or tag-based (e.g., CacheResponse::for()->withTags(['posts'])).
  • You need flexible caching (stale-while-revalidate) for dashboards or semi-dynamic content.
  • Your team prefers Laravel-native solutions over reverse proxies (e.g., Varnish) or CDNs for full-page caching.

Look elsewhere if:

  • Your app relies heavily on POST/PUT/DELETE requests (this package targets GET responses only).
  • You need sub-second cache invalidation (e.g., real-time updates). Consider Redis pub/sub or database triggers instead.
  • Your responses are highly dynamic (e.g., personalized content per user session). Use fragment caching (@cache) or Edge Side Includes (ESI).
  • You’re using Laravel <11 or PHP <8.4. Requires upgrades or a custom fork.
  • You need fine-grained control over cache keys (e.g., excluding query params). Extend the package or use Laravel’s built-in cache middleware.
  • Your infrastructure lacks Redis/Memcached (default storage). Supports database storage but with lower performance.

How to Pitch It (Stakeholders)

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:

  • Zero config for 80% use cases: Just wrap routes in CacheResponse::for(minutes(10)).
  • Flexible caching: Stale-while-revalidate for dashboards (FlexibleCacheResponse).
  • Laravel 12/13 ready: Supports PHP 8.5 and modern Laravel features.
  • Extensible: Add #[Cache] attributes to controllers for granular control.
  • Debug-friendly: Headers show cache status (e.g., 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:

  • One line to cache a route: Route::middleware(CacheResponse::for(hours(1)))->get('/...').
  • Flexible caching: Stale responses during refresh (FlexibleCacheResponse).
  • Tag invalidation: Clear cache by tag (e.g., ResponseCache::clear(['posts'])).
  • No Varnish needed: Works entirely in Laravel. Gotchas:
  • Only caches GET requests with text responses (no images, PDFs, or binary data).
  • Cache keys include full URL + headers, so ?sort=asc and ?sort=desc get separate caches.
  • Debug headers help verify cache hits/misses. Let’s start by caching /docs and /pricing—low risk, high reward."
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai