Answer the question
In order to leave comments, you need to log in
Why is the data not being retrieved from the cache?
There is an api written in lumen. A request for a bunch of orders generates a large amount of data (during the resource assembly, a bunch of data is pulled up, including raw requests to the database). It was decided to cache each order, and radish was chosen as the cache driver.
$orderIds = $request->list;
// Получаем ордера из кеша
$cachedOrders = Cache::tags($orderIds)->get('orders-resource') ?? [];
// Ищем айдишники, которых в кеше не было
$nonCachedIds = count($cachedOrders) === 0 ? $orderIds : $cachedOrders->whereNotIn('id', $orderIds);
// Получаем из базы не закешированные ордера
$fromDbOrders = Order::withTrashed()->with('comments')->findMany($nonCachedIds);
foreach ($fromDbOrders as $order) {
$orderResourced = OrderResource::make($order)->toArray($request);
$cachedOrders[] = $orderResourced;
Cache::tags($order->id)->put(
"orders-resource",
$orderResourced,
Carbon::SECONDS_PER_MINUTE * 10000
);
}
return response()->json(new Report(
"200",
$cachedOrders,
"Список заказов для базы данных",
$requestId
));
dd($cachedOrders);
I get emptiness. Perhaps I misunderstand the concept of tags? it will be difficult to do without them, because. Several caches will be linked to one order and there will be a need to clear everything related to a specific order.
Answer the question
In order to leave comments, you need to log in
Tags are not suitable for this application. I use it only to clear the cache by tags.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question