Implement a caching mechanism
This commit is contained in:
@@ -11,6 +11,10 @@ final class CategoryController extends BaseController
|
||||
#[Route('/category/{category}', name: 'app_category')]
|
||||
public function __invoke(string $category): Response
|
||||
{
|
||||
if($this->cache->getItem('list_category_'.$category)->isHit()) {
|
||||
return $this->render('productList.html.twig', ['listType' => 'category_'.$category]);
|
||||
}
|
||||
|
||||
$products = Product::with('price')
|
||||
->selectRaw('products.*')
|
||||
->distinct('products.id')
|
||||
@@ -19,6 +23,7 @@ final class CategoryController extends BaseController
|
||||
->orderByDesc('starred')
|
||||
->orderByDesc('created_by')
|
||||
->get();
|
||||
return $this->render('productList.html.twig', ['products' => $products]);
|
||||
|
||||
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'category_'.$category]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user