Leaseweb / LswMemcacheBundle

Symfony bundle for Memcache Doctrine caching and session storage in the Web Debug Toolbar.
MIT License
202 stars 57 forks source link

Add LswMemcache to multiple Doctrine entity manager #59

Open odoucet opened 8 years ago

odoucet commented 8 years ago

Documentation already gives information about how to add LswMemcacheBundle support on Doctrine (see https://github.com/LeaseWeb/LswMemcacheBundle#doctrine-support) But even if this is well handled for default entity manager, it seems it does not work for multiple entity managers :

When using executeCacheQuery() we get : Trying to cache a query but no result driver is configured.

Another way to check :

dump($this->get('doctrine')->getManager('metrics')->
    getConnection()->getConfiguration()->getResultImpl()); 
// dump NULL

Copy of YAML :

lsw_memcache:
    pools:
        default:
            servers:
              - { host: 127.0.0.1, tcp_port: 11211 }
    doctrine:
        metadata_cache:
            pool: default
            entity_manager: [default, metrics]
            document_manager: default
        result_cache:
            pool: default
            entity_manager: [default, metrics]
            prefix: "result_"
        query_cache:
            pool: default
            entity_manager: [default, metrics]

If we try to add the cache class ourself, we end with an error :

$cache = $this->get('memcache.default');
$config = $this->get('doctrine')->getManager('metrics')->getConnection()->getConfiguration();
$config->setResultCacheImpl($cache);

This gives this error : Argument 1 passed to Doctrine\DBAL\Configuration::setResultCacheImpl() must implement interface Doctrine\Common\Cache\Cache, instance of Lsw\MemcacheBundle\Cache\AntiDogPileMemcache given.

mevdschee commented 8 years ago

When you try to add the cache yourself, you should instantiate a "Lsw\MemcacheBundle\Doctrine\Cache\MemcacheCache" class and then call "setMemcache()" on the created object to set the client.

odoucet commented 8 years ago

OK, updating the doc will be great about it :)

mevdschee commented 8 years ago

Well, we still have not figured out why "executeCacheQuery" gives an error and why it seems it does not work for multiple entity managers. Or did you find reasons for that?

odoucet commented 8 years ago

Not yet, And I have to admit I've changed my code after I encountered this bug to cache the query result myself.

2015-10-01 22:58 GMT+02:00 Maurits van der Schee notifications@github.com:

Well, we still have not figured out why "executeCacheQuery" gives an error and why it seems it does not work for multiple entity managers. Or did you find reasons for that?

— Reply to this email directly or view it on GitHub https://github.com/LeaseWeb/LswMemcacheBundle/issues/59#issuecomment-144846530 .

mevdschee commented 8 years ago

OK, thank you. I will try to reproduce it and update this thread.