Connect Doctrine to memcached pool
Maybe someone knows how to hook Doctrine to memcached pool to use it as cache driver?
I checked the official package documentation and many other sources, but couldn't find any examples of such a connection.
Also due to the source code, I couldn't find any use cases for the pool, but maybe I am missing something.
source to share
Not tested, 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 cannot test it, but it is a combination of several methods known to work.
UPDATE:, updated based on CrazySquirrel results.
source to share
Thanks to lxg for your ideas. I have built the correct configuration using your ideas. Below you will find the correct definition of a service:
app 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]]
source to share