Code snippets
Code snippets
Copy-ready answers to everyday coding questions, each with a short explanation. Laravel, PHP, JavaScript, SQL, Bash and more.
2 snippets tagged #cache · Show all
PHP
October 10, 2026
Laravel Cache::flexible stale-while-revalidate caching
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 page...
<?php
use Illuminate\Support\Facades\Cache;
PHP
October 8, 2026
Laravel cache expensive query with Cache::remember
Runs the query once and serves the result from cache for the given time. Use it for heavy queries on pages with lots of traffic, and forget the key when the dat...
<?php
use Illuminate\Support\Facades\Cache;