Permalink
Browse files

Add CacheWarmer for proxy directory

  • Loading branch information...
1 parent 4aed418 commit 891ae44cd1a27a64b3a0508b7a4cf80b80f0905c @beberlei beberlei committed Jun 23, 2011
Showing with 62 additions and 1 deletion.
  1. +55 −0 CacheWarmer/ProxyCacheWarmer.php
  2. +1 −1 DependencyInjection/DoctrineCouchDBExtension.php
  3. +6 −0 Resources/config/odm.xml
@@ -0,0 +1,55 @@
+<?php
+
+namespace Doctrine\Bundle\CouchDBBundle\CacheWarmer;
+
+use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+class ProxyCacheWarmer implements CacheWarmerInterface
+{
+ private $container;
+
+ /**
+ * Constructor.
+ *
+ * @param ContainerInterface $container
+ */
+ public function __construct(ContainerInterface $container)
+ {
+ $this->container = $container;
+ }
+
+ /**
+ * This cache warmer is not optional, without proxies fatal error occurs!
+ *
+ * @return false
+ */
+ public function isOptional()
+ {
+ return false;
+ }
+
+ public function warmUp($cacheDir)
+ {
+ foreach ($this->container->getParameter('doctrine_couchdb.document_managers') as $dmName) {
+ $dm = $this->container->get($dmName);
+
+ // we need the directory no matter the proxy cache generation strategy
+ if (!file_exists($proxyCacheDir = $dm->getConfiguration()->getProxyDir())) {
+ if (false === @mkdir($proxyCacheDir, 0777, true)) {
+ throw new \RuntimeException(sprintf('Unable to create the Doctrine CouchDB Proxy directory "%s".', dirname($proxyCacheDir)));
+ }
+ } elseif (!is_writable($proxyCacheDir)) {
+ throw new \RuntimeException(sprintf('The Doctrine CouchDB Proxy directory "%s" is not writeable for the current system user.', $proxyCacheDir));
+ }
+
+ // if proxies are autogenerated we don't need to generate them in the cache warmer
+ /*if ($dm->getConfiguration()->getAutoGenerateProxyClasses()) {
@stof

stof Jun 23, 2011

Member

Why is it commented ?

@beberlei

beberlei Jun 23, 2011

Owner

CouchDB currently alwas generates proxies. Havent gotten into supporting the other approch yet, since there were no commands to generate the proxies before.

+ continue;
+ }
+
+ $classes = $dm->getMetadataFactory()->getAllMetadata();
+ $dm->getProxyFactory()->generateProxyClasses($classes);*/
+ }
+ }
+}
@@ -188,7 +188,7 @@ protected function loadOdmDocumentManagerMappingInformation(array $documentManag
$odmConfig->addMethodCall('addDesignDocument', array(
$documentManager['view_name'],
'Doctrine\CouchDB\View\FolderDesignDocument',
- array($bundleDir."/Resources/couchdb/" . $documentManager['name'])
+ $bundleDir."/Resources/couchdb/" . $documentManager['name']
));
}
}
View
@@ -18,6 +18,7 @@
<parameter key="doctrine_couchdb.odm.cache.memcache_port">11211</parameter>
<parameter key="doctrine_couchdb.odm.cache.memcache_instance.class">Memcache</parameter>
<parameter key="doctrine_couchdb.odm.cache.xcache.class">Doctrine\Common\Cache\XcacheCache</parameter>
+ <parameter key="doctrine_couchdb.odm.proxy_cache_warmer.class">Doctrine\Bundle\CouchDBBundle\CacheWarmer\ProxyCacheWarmer</parameter>
<parameter key="doctrine_couchdb.odm.metadata.driver_chain.class">Doctrine\ODM\CouchDB\Mapping\Driver\DriverChain</parameter>
<parameter key="doctrine_couchdb.odm.metadata.annotation.class">Doctrine\ODM\CouchDB\Mapping\Driver\AnnotationDriver</parameter>
@@ -32,6 +33,11 @@
<argument type="service" id="annotation_reader" />
</service>
+ <service id="doctrine_couchdb.odm.proxy_cache_warmer" class="%doctrine_couchdb.odm.proxy_cache_warmer.class%" public="false">
+ <tag name="kernel.cache_warmer" />
+ <argument type="service" id="service_container" />
+ </service>
+
<service
id="doctrine_couchdb.odm.configuration"
class="%doctrine_couchdb.odm.configuration.class%"

0 comments on commit 891ae44

Please sign in to comment.