-
Hi, i'm using fractal + pagerfanta for pagination my result in my project. I wonder how can i apply result cache in my query builder when using pagerfanta? $adapter = new QueryAdapter($result);
$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage($limitPerPage);
$pagerfanta->setCurrentPage($page);
$paginatorAdapter = new PagerfantaPaginatorAdapter($pagerfanta, function(int $page) use ($request, $limitPerPage) {
$route = $request->attributes->get('_route');
$inputParams = $request->attributes->get('_route_params');
$newParams = array_merge($inputParams, $request->query->all());
$newParams['page'] = $page;
$newParams['limit'] = $limitPerPage;
return $this->router->generate($route, $newParams, UrlGeneratorInterface::ABSOLUTE_URL);
});
$resource = new Collection($pagerfanta->getCurrentPageResults(), $transformer, 'data');
$resource->setPaginator($paginatorAdapter); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
In one of my projects, we use the result cache with the Doctrine ORM query adapter in a few different circumstances, for those you'd just need to call There isn't a way to use the result cache with the Doctrine DBAL query adapter, the query builder's |
Beta Was this translation helpful? Give feedback.
In one of my projects, we use the result cache with the Doctrine ORM query adapter in a few different circumstances, for those you'd just need to call
$qb->enableResultCache()
as you would elsewhere before getting the current page's results. Do make sure your cache is pagination aware (and if your request supports them, filters as well) that way you aren't serving the wrong page's results because of an invalid cache.There isn't a way to use the result cache with the Doctrine DBAL query adapter, the query builder's
execute()
method doesn't give a way to call the connection'sexecuteQuery()
method with a query cache profile. So if you wanted to use a result cache with the DBAL, you'd need …