Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Redis for caching doctrine result in Symfony 2 application

I am trying to use Redis to cache query result and APC for metacache. As per Symfony docs all I need to do is.

doctrine:
    orm:
        auto_mapping: true
        metadata_cache_driver: apc
        result_cache_driver:
            type: redis
            host: localhost
            instance_class: Redis

Is this the right way to configure the cache property for doctrine? Also when I google "use redis with symfony" I get results which tells me to use SNCRedis bundle.

Is it necessary to use SNCRedis bundle to use Redis for doctrine in Symfony? Also what benefit it provides on top of Symfony defaults. I am just bit confused here since documentation is sparse when it comes to caching in Symfony with related to Doctrine. Can someone please give me any insight in this matter.

like image 928
nicholasnet Avatar asked Aug 13 '15 15:08

nicholasnet


1 Answers

The configuration you've added for result cache only configures the strategy to use. You still need to explicitly tell doctrine to cache results for specific queries:

$query->useResultCache(true);

Learn more about it in the Doctrine's Cache docs.

Documentation in Symfony is sparse, as this is not really a Symfony specific thing. Read the doctrine documentation instead. Only use Symfony docs to learn how to configure Doctrine.

You don't need any Redis bundles, as Redis caching strategy is implemented by doctrine with the doctrine/cache package. You don't have to worry how to use it. Simply configure the cache as described in the docs.

like image 138
Jakub Zalas Avatar answered Nov 07 '22 04:11

Jakub Zalas