What's new
Flexible caching
For pages where brief staleness is acceptable, you can now use flexible caching. After the lifetime expires, the stale response is still served instantly while the cache refreshes in the background. Once the grace period is over, the cache is considered expired and the next request will be fully recalculated:
use Spatie\ResponseCache\Middlewares\FlexibleCacheResponse;
Route::get('/dashboard', [DashboardController::class, 'index'])
->middleware(FlexibleCacheResponse::for(lifetime: hours(1), grace: minutes(5)));PHP attributes for cache configuration
You can now use attributes on controllers instead of middleware parameters:
use Spatie\ResponseCache\Attributes\Cache;
use Spatie\ResponseCache\Attributes\FlexibleCache;
use Spatie\ResponseCache\Attributes\NoCache;
#[Cache(lifetime: 3600, tags: ['dashboard'])]
public function index() { ... }
#[FlexibleCache(lifetime: 3600, grace: 300)]
public function show() { ... }
#[NoCache]
public function admin() { ... }Other changes
- Add support for PHP 8.4 and Laravel 12
- Drop support for PHP 8.3 and below, Laravel 11 and below
- Rename event classes to use
Eventsuffix (e.g.CacheMissed→CacheMissedEvent) - Replace
cacheRequestUntil()withcacheLifetimeInSeconds()inCacheProfileinterface - Replace
CacheResponse::using()withCacheResponse::for()andFlexibleCacheResponse::for() - Improved debug headers configuration
- Fix return types in Facade PHPDoc for
clear()andforget()
Full Changelog: 7.7.2...8.0.0