Answer the question
In order to leave comments, you need to log in
How to cache data from the database every 15 minutes?
Good day!
A large amount of data is taken from the database to plot, but the data only changes every 15 minutes. How to make the data cached and no longer wait for the selection, but immediately give it to the user from the cache?
Does Laravel have any tools?
Answer the question
In order to leave comments, you need to log in
Everything is written in the documentation.
For example.
$result = DB::select("SELECT * FROM goods"); // пример запроса
if(!Cache::has('goods')){
// если в кэше нет то сохраняем в кэш
Cache::put('goods', $result, 15); // на 15 минут сохраняем в кэш
$goods = Cache::get('goods'); // получаем из кэша
}else{
// получаем из кэша
$goods = Cache::get('goods'); // получаем из кэша
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question