I
I
Ilya2020-06-17 12:49:56
Laravel
Ilya, 2020-06-17 12:49:56

How to keep the old cache value if the new one is not available?

$response = \Cache::remember('cache-key', 3600, function () {

  $response = Client::get(); //http запрос

  if ($response) {
    return $response;
  }

  return false;
});

There is a third-party service that we access once an hour and cache the response.
The cache lifetime has expired, but the third-party server is unavailable.
We need to extend the lifetime by another hour and get the old value from the cache.
How?

The point is that if a third-party service is not available, then you need to use the old value that was in the cache.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2020-06-17
@Nc_Soft

\Cache::rememberForever

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question