Skip to content

Instantly share code, notes, and snippets.

@Saeven
Last active February 25, 2017 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Saeven/31fd88b3a02c12a7c12299b38f4b98bd to your computer and use it in GitHub Desktop.
Save Saeven/31fd88b3a02c12a7c12299b38f4b98bd to your computer and use it in GitHub Desktop.
Doctrine & Memcached
<?php
/*
* Typical database config
*/
// ....
'doctrine' => [
'configuration' => [
'orm_default' => [
'metadata_cache' => 'memcached',
'query_cache' => 'memcached',
'result_cache' => 'memcached',
'datetime_functions' => [
'Date' => Date::class,
],
],
],
'cache' => [
'memcached' => [
'instance' => 'doctrine.cache.memcached',
],
],
'connection' => [
'orm_default' => [
'driverClass' => '\Application\Model\Doctrine\DBAL\Driver\PDOMySql\Driver',
'wrapperClass' => '\Application\Model\Doctrine\DBAL\Connection',
'params' => [
'host' => '***',
'port' => '3306',
'user' => '***',
'password' => '***',
'dbname' => '***',
'driverOptions' => [
'x_reconnect_attempts' => 10,
1002 => 'SET NAMES utf8',
],
],
],
],
],
// ....
/*
* Factory for cache adapter
*/
// ....
'service_manager' => [
'factories' => [
'doctrine.cache.memcached' => function ($sm) {
$cache = new \Doctrine\Common\Cache\MemcachedCache();
$memcached = new \Memcached();
$memcached->addServer('localhost', 11211);
$cache->setMemcached($memcached);
return $cache;
},
],
],
// ....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment