Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
Add CacheWarmer for proxy directory
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Jun 23, 2011
1 parent 4aed418 commit 891ae44
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
55 changes: 55 additions & 0 deletions CacheWarmer/ProxyCacheWarmer.php
@@ -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()) {

This comment has been minimized.

Copy link
@stof

stof Jun 23, 2011

Member

Why is it commented ?

This comment has been minimized.

Copy link
@beberlei

beberlei Jun 23, 2011

Author Member

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);*/
}
}
}
2 changes: 1 addition & 1 deletion DependencyInjection/DoctrineCouchDBExtension.php
Expand Up @@ -188,7 +188,7 @@ protected function loadOdmDocumentManagerMappingInformation(array $documentManag
$odmConfig->addMethodCall('addDesignDocument', array( $odmConfig->addMethodCall('addDesignDocument', array(
$documentManager['view_name'], $documentManager['view_name'],
'Doctrine\CouchDB\View\FolderDesignDocument', 'Doctrine\CouchDB\View\FolderDesignDocument',
array($bundleDir."/Resources/couchdb/" . $documentManager['name']) $bundleDir."/Resources/couchdb/" . $documentManager['name']
)); ));
} }
} }
Expand Down
6 changes: 6 additions & 0 deletions Resources/config/odm.xml
Expand Up @@ -18,6 +18,7 @@
<parameter key="doctrine_couchdb.odm.cache.memcache_port">11211</parameter> <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.memcache_instance.class">Memcache</parameter>
<parameter key="doctrine_couchdb.odm.cache.xcache.class">Doctrine\Common\Cache\XcacheCache</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.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> <parameter key="doctrine_couchdb.odm.metadata.annotation.class">Doctrine\ODM\CouchDB\Mapping\Driver\AnnotationDriver</parameter>
Expand All @@ -32,6 +33,11 @@
<argument type="service" id="annotation_reader" /> <argument type="service" id="annotation_reader" />
</service> </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 <service
id="doctrine_couchdb.odm.configuration" id="doctrine_couchdb.odm.configuration"
class="%doctrine_couchdb.odm.configuration.class%" class="%doctrine_couchdb.odm.configuration.class%"
Expand Down

0 comments on commit 891ae44

Please sign in to comment.