Laravel Cache::flexible stale-while-revalidate caching
PHP Dasun Kalupahana 337 views
<?php
use Illuminate\Support\Facades\Cache;
// Fresh for 5 seconds, then served stale for up to 10 more seconds while it refreshes.
$stats = Cache::flexible('dashboard.stats', [5, 10], function () {
return [
'users' => \App\Models\User::count(),
'orders' => \App\Models\Order::count(),
];
});
Serves the cached value instantly, even after it goes stale, and refreshes it in the background after the response is sent. Use it for slow queries on busy pages so no visitor waits on a cache miss. Needs Laravel 11.23+.
Learn more on the blog
MySQL
PostgreSQL vs MySQL Performance: Real Benchmarks Compared
Last updated: 7 November 2026. See the update log at the end."Which...
8 min read
PHP
How to Detect and Fix PHP Memory Leaks
Last updated: 5 November 2026. See the update log at the end.In...
9 min read
Docker
Docker Build Too Slow? 10 Ways to Speed It Up
A slow Docker build usually has one of a few causes: you...
8 min read