脚本宝典收集整理的这篇文章主要介绍了php – Symfony2 – 如何使用多个应用程序设置Doctrine APC缓存前缀,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我们已经在我们的服务器上运行了多个Symfony应用程序,但由于所有主题ORM缓存条目都以“sf2”为前缀,我们似乎在各个站点中获得缓存污染.
第一个建议使用PRojectConfiguration.class.PHP – 但这似乎是Symfony 1的事情.
下一个可能的解决方案是使用ApcUniversalClassLoader类(根据SO:Multiple Symfony2 Sites using APC Cache上的这个问题).
问题是我们的设置使用composer进行自动加载,因此我们不能简单地按照该示例使用代码.
APC的类缓存方面很好,您可以在前端控制器中设置密钥,但它不会设置doctrine缓存的密钥.
有没有人有任何想法,因为目前我们不得不禁用APC作为除了第一个应用程序之外的所有学说.
Frontcontroller:
<?PHP use Symfony\component\ClassLoader\ApcClassLoader; use Symfony\Component\HttpFoundation\Request; require_once __DIR__.'/../app/bootstrap.PHP.cache'; // Use APC for autoloading to improve PErformance. // Change 'sf2' to a unique prefix in order to prevent cache key conflicts // wITh other applications also using APC. $loader = new ApcClassLoader('app_1',$loader); $loader->register(true); require_once __DIR__.'/../app/AppKernel.PHP'; $kernel = new AppKernel('prod',false); $kernel->loadClassCache(); // wrap the default AppKernel with the AppCache one require_once __DIR__.'/../app/AppCache.PHP'; $kernel = new AppCache($kernel); Request::enableHttpMethodParameteroverride(); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request,$response);
– 澄清 –
只是为了澄清,上面的代码引用了类的apc缓存,这可以如上所述并且很好.我们似乎无法改变的是Doctrine ORM APC条目的默认命名空间,这些似乎是固定的,因此与每个正在运行的实例冲突.
– 更新 –
在尝试Zerrvox建议设置命名空间后,它似乎没有用,主缓存仍在使用默认命名空间.如果在清除缓存时随机生成它们就不会那么糟糕,但是我的流浪盒和活动框上的默认命名空间是相同的,并且缓存是在单独的框上生成的,因此它显然不是随机的.
缓存中的appProdProjectContainer类中的这些方法仍然引用默认命名空间.
protected function getDoctrineCache_Providers_Doctrine_Orm_DefaultMetadataCacheService() { .... $instance->setnamespace('sf2orm_default_9e755ef08ba52b507455ecd06d0a648985c9593b15aca1522b4725acaaf77ce6'); return $instance; } // Same for... protected function getDoctrineCache_Providers_Doctrine_Orm_DefaultQueryCacheService protected function getDoctrineCache_Providers_Doctrine_Orm_DefaultResultCacheService
无论如何,您可以创建自己的APC缓存服务,可以通过在Symfony中定义服务来使用它(yML)
app.doctrine.apc_cache: class: Doctrine\Common\Cache\ApcCache calls: - [setNamespace,["app_namespace"]]
– 更新 –
您是否将定义的服务指定为doctrine的元数据缓存.请参阅Doctrine软件包配置http://symfony.com/doc/current/reference/configuration/doctrine.html#caching-drivers的配置参考
doctrine: orm: Metadata_cache_driver: type: service id: app.doctrine.apc_cache
以上是脚本宝典为你收集整理的php – Symfony2 – 如何使用多个应用程序设置Doctrine APC缓存前缀全部内容,希望文章能够帮你解决php – Symfony2 – 如何使用多个应用程序设置Doctrine APC缓存前缀所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。