Add Doctrine cache configuration

[MAILPOET-2014]
This commit is contained in:
Jan Jakeš
2019-05-09 15:05:49 +02:00
committed by M. Shull
parent 7a69c23967
commit e515f06d02

View File

@@ -2,7 +2,9 @@
namespace MailPoet\Doctrine;
use MailPoet\Config\Env;
use MailPoetVendor\Doctrine\Common\Annotations\SimpleAnnotationReader;
use MailPoetVendor\Doctrine\Common\Cache\ArrayCache;
use MailPoetVendor\Doctrine\Common\Cache\FilesystemCache;
use MailPoetVendor\Doctrine\Common\Proxy\AbstractProxyFactory;
use MailPoetVendor\Doctrine\ORM\Configuration;
@@ -27,6 +29,7 @@ class ConfigurationFactory {
$this->configureMetadata($configuration);
$this->configureProxies($configuration);
$this->configureCache($configuration);
if (!$this->is_dev_mode) {
$configuration->ensureProductionSettings();
@@ -55,4 +58,17 @@ class ConfigurationFactory {
: AbstractProxyFactory::AUTOGENERATE_NEVER
);
}
private function configureCache(Configuration $configuration) {
if ($this->is_dev_mode) {
$cache = new ArrayCache();
} else {
$cache_dir = Env::$cache_path . '/doctrine';
$cache = new FilesystemCache($cache_dir);
$cache->setNamespace('mp3-' . md5($cache_dir) . '-');
}
$configuration->setQueryCacheImpl($cache);
$configuration->setResultCacheImpl($cache);
}
}