Dinesh Uprety
@dineshuprety ·
Public
Know whether a cache item was warm
PHPLaravel 13 API example based on official Laravel documentation. Source: https://api.laravel.com/docs/13.x/Illuminate/Cache/Repository.html#method_rememberWithWarmth
PHP
CodeSnap // free canvas
Know whether a cache item was warm
<?php
use Illuminate\Support\Facades\Cache;
[$products, $warm] = Cache::rememberWithWarmth(
'products:featured',
now()->addHour(),
fn () => Product::featured()->get(),
);
return response()->json($products)
->header('X-Cache', $warm ? 'HIT' : 'MISS');
// Further reading: https://api.laravel.com/docs/13.x/Illuminate/Cache/Repository.html#method_rememberWithWarmth