github spatie/laravel-responsecache 8.0.0

latest release: 8.1.0
8 hours ago

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 Event suffix (e.g. CacheMissedCacheMissedEvent)
  • Replace cacheRequestUntil() with cacheLifetimeInSeconds() in CacheProfile interface
  • Replace CacheResponse::using() with CacheResponse::for() and FlexibleCacheResponse::for()
  • Improved debug headers configuration
  • Fix return types in Facade PHPDoc for clear() and forget()

Full Changelog: 7.7.2...8.0.0

Don't miss a new laravel-responsecache release

NewReleases is sending notifications on new releases.