Answer the question
In order to leave comments, you need to log in
How to properly cache a long request so that parallel requests wait until the cache is generated?
The picture is generated for 10 seconds.
Is it possible to make it start being generated and placed in the cache the first time the picture is accessed, while other parallel requests (while the picture is being generated) would wait for the cache to be ready and return it from the cache?
Answer the question
In order to leave comments, you need to log in
Yes, there are locks for that.
https://laravel.com/docs/8.x/cache#managing-locks
use Illuminate\Support\Facades\Cache;
$lock = Cache::lock('pic' . $id, 10);
if ($lock->get()) {
// генерируем картинку
$lock->release();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question