Doctrine query result cache with API Platform

In Symfony, i used to enable query results cache this way:

Configuration in doctrine.yaml

doctrine:
    orm:
        metadata_cache_driver: apcu
        result_cache_driver: apcu
        query_cache_driver: apcu

services:
    doctrine.result_cache_provider:
        class: SymfonyComponentCacheDoctrineProvider
        public: false
        arguments:
            - '@doctrine.result_cache_pool'
    doctrine.system_cache_provider:
        class: SymfonyComponentCacheDoctrineProvider
        public: false
        arguments:
            - '@doctrine.system_cache_pool'

framework:
    cache:
        pools:
            doctrine.result_cache_pool:
                adapter: cache.app
            doctrine.system_cache_pool:
                adapter: cache.system

Enabling result caching in entity repository:

$builder = $this->createQueryBuilder('a');

$builder->setMaxResults(1);

return $builder
    ->getQuery()
    ->useQueryCache(true)
    ->setQueryCacheLifetime(43200)
    ->useResultCache(true)
    ->setResultCacheLifetime(21600)
    ->getOneOrNullResult();

I can’t figure out what is the right way to implement query result cache using API Platform since i am not using the repositories manually.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *