Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect Doctrine to memcached pool

Perhaps anybody know, how to connect Doctrine to memcached pool, to use it as a cache driver?

I've check official bundle documentation, and lot of another sources, but didn't find any examples of such connection.

Also due to source code, I could not find any options to use pool, but perhaps I miss something.

like image 562
CrazySquirrel Avatar asked Jan 10 '23 23:01

CrazySquirrel


2 Answers

Didn't test, but the following should work:

in app/config/parameters.yml, set/add

parameters:
    memcached.servers:
        - { host: 127.0.0.1, port: 11211 }
        - { host: 127.0.0.2, port: 11211 }

in app/config/config.yml set/add

services:
    memcache:
        # class 'Memcache' or 'Memcached', depending on which PHP module you use
        class: Memcache
        calls:
            - [ addServers, [ %memcached.servers% ]]

    doctrine.cache.memcached:
        class: Doctrine\Common\Cache\MemcachedCache
        calls:
            - [setMemcached, [@memcached]]

in app/config/config_prod.yml, set

doctrine:
    orm:
        metadata_cache_driver:
            type: service
            id: doctrine.cache.memcached
        query_cache_driver:
            type: service
            id: doctrine.cache.memcached
        result_cache_driver:
            type: service
            id: doctrine.cache.memcached

As I said, I can't test it, but this is the combination of several known-to-work techniques.

UPDATE: solution updated based on CrazySquirrel's findings.

like image 137
lxg Avatar answered Jan 17 '23 04:01

lxg


Thanks lxg for your ideas. I've build right configuration using your ideas. Please find correct service definition below:

application config:

result_cache_driver:
        type: service
        id:  doctrine.cache.memcached

service.yml

memcached:
  class: Memcached
  calls:
      - [ addServers, [ %memcached_servers% ]]

doctrine.cache.memcached:
      class: Doctrine\Common\Cache\MemcachedCache
      calls:
        - [setMemcached, [@memcached]]
like image 27
CrazySquirrel Avatar answered Jan 17 '23 04:01

CrazySquirrel