Skip to content

Commit 9ab08bb

Browse files
committed
feat(cache-middleware): try using Cache::remember notation
1 parent 80c5c21 commit 9ab08bb

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

‎app/Http/Middleware/CacheMiddleware.php‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
class CacheMiddleware
1010
{
11+
const TTL_DAYS = 7 * 86400;
12+
1113
/**
1214
* Handle an incoming request.
1315
*
@@ -18,14 +20,10 @@ class CacheMiddleware
1820
public function handle(Request $request, Closure $next)
1921
{
2022
$key = md5($request->fullUrl());
21-
if (! Cache::has($key)) {
22-
$value = $next($request)->withHeaders([
23-
'X-Vapor-Base64-Encode' => 'True',
24-
'Cache-Control' => 'max-age=2592000, public',
25-
]);
26-
Cache::put($key, $value);
27-
}
2823

29-
return Cache::get($key);
24+
return Cache::remember($key, self::TTL_DAYS, fn () => $next($request)->withHeaders([
25+
'X-Vapor-Base64-Encode' => 'True',
26+
'Cache-Control' => 'max-age=2592000, public',
27+
]));
3028
}
3129
}

0 commit comments

Comments
 (0)