Skip to content

Commit 5d38146

Browse files
committed
Allow for setting a cache namespace
If `cache_namespace` is set, `setNamespace` will be called on the resulting cache instance if it is a Doctrine CacheProvider instance. Doctrine's CacheProvider will take care of normalizing this call for various backends based on its own rules. $app->register( new Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider, array( 'orm.em.options' => array( 'cache_namespace' => 'appname_', 'metadata_cache' => 'apc', 'query_cache' => 'apc', 'mappings' => array( array(), ), ), ) ); Thanks to @asiermarques for this work. Closes #15 Closes #16
1 parent 24be501 commit 5d38146

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Dflydev/Pimple/Provider/DoctrineOrm/DoctrineOrmServiceProvider.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\Common\Cache\ApcCache;
1515
use Doctrine\Common\Cache\ArrayCache;
16+
use Doctrine\Common\Cache\CacheProvider;
1617
use Doctrine\Common\Cache\MemcacheCache;
1718
use Doctrine\Common\Cache\MemcachedCache;
1819
use Doctrine\Common\Cache\XcacheCache;
@@ -192,7 +193,13 @@ public function register(\Pimple $app)
192193
return $app[$cacheInstanceKey];
193194
}
194195

195-
return $app[$cacheInstanceKey] = $app['orm.cache.factory']($driver, $options[$cacheNameKey]);
196+
$cache = $app['orm.cache.factory']($driver, $options[$cacheNameKey]);
197+
198+
if(isset($options['cache_namespace']) && $cache instanceof CacheProvider) {
199+
$cache->setNamespace($options['cache_namespace']);
200+
}
201+
202+
return $app[$cacheInstanceKey] = $cache;
196203
});
197204

198205
$app['orm.cache.factory.backing_memcache'] = $app->protect(function() {

0 commit comments

Comments
 (0)