Laravel Response Cache v8: Flexible Caching Explained

Laravel Response Cache v8: Flexible Caching Explained

Alex Rollin
Alex Rollin
February 21, 2026
February 21, 2026

Spatie released Laravel Response Cache v8 in January 2025, introducing what they call "flexible caching" to the popular package. For Laravel developers dealing with performance challenges, this update addresses one of the main complaints about previous versions: the all-or-nothing approach to caching. Version 8 introduces granular control over when, how, and for whom responses get cached.

What Led to This Update

Laravel Response Cache has been a popular choice for Laravel developers wanting to speed up their applications without adding external infrastructure like Varnish or CDN caching. This Laravel caching package provides a straightforward approach to Laravel performance optimization. The package works by caching entire HTTP responses, so when a visitor requests the same page twice, the second request skips all the application logic and returns the cached version directly. This Laravel HTTP response cache method is one of the most effective ways to speed up Laravel application response times.

The package has been around for years, with over 10 million downloads on Packagist and around 2,400 GitHub stars. Spatie, the Belgian company behind it, maintains over 300 open-source packages.

Previous versions had a limitation though. While you could create custom cache profiles, the logic for determining what gets cached and for how long was fairly rigid. Developers often had to work around these constraints when building applications with complex caching requirements, like multi-tenant systems or apps with role-based content.

What Changed in Version 8

More Flexible Cache Profiles

The biggest change is how you define caching rules. Laravel cache profiles in v8 provide unprecedented flexibility for complex scenarios. Version 8 lets you create custom cache profile classes with fine-grained control over:

  • User-based caching rules (cache different responses for different user types)
  • Header-based logic (vary cache based on Accept or Accept-Language headers)
  • Query parameter filtering
  • Dynamic cache durations based on request attributes

Here's what a custom profile looks like in v8:

namespace App\CacheProfiles;

use Spatie\ResponseCache\CacheProfiles\BaseCacheProfile;
use Illuminate\Http\Request;

class CustomCacheProfile extends BaseCacheProfile
{
    public function shouldCacheRequest(Request $request): bool
    {
        if ($request->is('api/*')) {
            return true;
        }
        
        return $request->isMethod('GET');
    }
    
    public function cacheRequestUntil(Request $request): DateTime
    {
        if ($request->is('static/*')) {
            return now()->addDay();
        }
        
        return now()->addMinutes(30);
    }
}

Better Cache Bypass Logic

Version 8 gives you more control over when to skip the cache entirely. Laravel cache bypass capabilities now include:

  • Specific cookies
  • Authentication status
  • Request headers
  • Query parameters

This matters for A/B testing, personalized content, and multi-tenant applications where different users need different responses. Multi-tenant Laravel caching is now significantly easier to implement with these granular bypass rules.

Improved Cache Invalidation

One of the trickier parts of response caching is knowing when to clear it. Laravel cache invalidation in Version 8 improves this with:

  • Selective cache invalidation (clear specific cached responses without flushing everything)
  • Better support for cache tags when using Redis
  • Model-based cache clearing through observers

Laravel cache tags Redis integration enables precise control over which cached responses to clear.

Laravel 11 Compatibility

The package now works fully with Laravel 11's simplified structure. Laravel 11 caching configuration has been streamlined, and this package takes full advantage of the new approach. Laravel middleware caching registration looks like this:

// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
    $middleware->web(append: [
        \Spatie\ResponseCache\Middlewares\CacheResponse::class,
    ]);
})

Configuration Improvements

The config file now supports more options:

'flexible_caching' => [
    'enabled' => true,
    'vary_headers' => ['Accept', 'Accept-Language'],
    'cache_lifetime_resolver' => null,
],

How This Affects Laravel Teams

For teams building content-heavy Laravel applications, marketing sites, or CMS-driven platforms, this update makes response caching a more realistic option. Previously, the rigidity of the caching profiles meant you either cached everything or had to write extensive workarounds.

Performance Expectations

Based on typical benchmarks, response caching can reduce page load times from 200-500ms to 5-15ms for complex pages. That's a 10-20x improvement in some cases. For teams seeking to reduce Laravel page load time, response caching delivers exceptional results. The actual numbers depend on your application complexity and server setup, but the principle holds: serving a cached response is always faster than rebuilding it.

Who Benefits Most

  • Teams running high-traffic public websites
  • Applications with mostly read-heavy traffic patterns
  • Projects where setting up Varnish or similar infrastructure isn't practical
  • Multi-tenant applications that previously couldn't use response caching

Any Laravel high traffic website can benefit from proper response caching configuration.

What Stays the Same

Some limitations remain. Response caching still requires careful handling of:

  • CSRF tokens in forms
  • Session-dependent content
  • Real-time data that changes frequently

Our Take on the Update

Working with high-traffic Laravel applications, we've found that response caching often gets overlooked in favor of query caching or partial view caching. The problem with the older approach was that it required too much custom code to handle real-world scenarios like user roles or content personalization.

Our team has been testing the v8 features on a few client projects, and the cleaner cache profile API makes a real difference. Instead of fighting against the package's assumptions, you can now express your caching rules directly in code. The improved cache invalidation is also helpful for CMS-style applications where content editors need their changes to appear immediately.

If you're already using Laravel Response Cache, the upgrade path should be straightforward. Check the release notes for any breaking changes in your custom profiles.

Wrapping Up

Laravel Response Cache v8 addresses the main flexibility complaints from earlier versions. The improved cache profiles, better bypass logic, and selective invalidation give developers the control they need for complex applications. Combined with Laravel 11 compatibility and performance improvements, this release makes response caching a stronger option for Laravel projects.

At Rollin, we recommend evaluating response caching early in your project planning, especially for content-heavy applications where infrastructure-level caching isn't available. If you're building a high-traffic Laravel application and want help setting up an effective caching approach, whether that's response caching, query caching, or view caching working together, our team can help you design a plan that matches your traffic patterns and content update frequency.

Share this article