I have a Symfony REST API application.
In repository I retrieve some data and use Doctrine Paginator for pagination, then in controller I serialize that data to JSON with Symfony Serializer.
Repository method:
public function getCategories($limit, $offset)
{
$qb = $this->em->createQueryBuilder()
->select('c')
->from('Category:Category', 'c')
->getQuery()->setFirstResult($offset)
->setMaxResults($limit);
$paginator = new Paginator($qb);
return ['total' => count($paginator), 'items' => $paginator];
}
And in controller:
$data = $this->serializer->serialize($data, 'json', $context);
return new JsonResponse($data, $code, [], true);
Now I want to implement caching of my data using Redis. How can I do it?
Should I inject serializer into repository, serialize my data there and store scalar values in Redis?
Or should I use Doctrine Result Cache(which says nothing about paginated queries)?