-
-
Save doctrinebot/6f33fc356cc1fd5c935a to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-1909 - https://github.com/doctrine/doctrine2/issues/2576
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Description of DoctrineCache | |
* @author justinas | |
*/ | |
class SCMS_Controller_Plugin_DoctrineCache extends Zend_Controller_Plugin_Abstract | |
{ | |
/** | |
* @var \Doctrine\Common\Cache\CacheProvider | |
*/ | |
private static $driver; | |
public function routeShutdown(Zend_Controller_Request_Abstract $request){ | |
/* @var $em \Doctrine\ORM\EntityManager */ | |
$em = Zend_Registry::get('em'); | |
$cacheDriver = $this->getCacheDriver(); | |
$cacheDriver->setNamespace(\SCMS\DbCache::CNS_CACHE); | |
$em->getConfiguration()->setResultCacheImpl($cacheDriver); | |
Zend_Registry::set('Cache_Driver', $cacheDriver); | |
} | |
/** | |
* | |
* @return \Doctrine\Common\Cache\CacheProvider | |
*/ | |
public static function getCacheDriver(){ | |
if (self::_getDriverName() == 'memcache') { | |
$config = \Zend_Registry::get('config'); | |
$cacheSrvs = $config['resources']['doctrine']['cache']['instances']['memcache']['options']['servers']; | |
$memcache = new Memcache(); | |
foreach($cacheSrvs as $srv){ | |
$memcache->addserver($srv['host'], $srv['port'], $srv['persistent'], $srv['weight'], $srv['timeout'], $srv['retryInterval'], $srv['status']); | |
} | |
self::$driver = new \Doctrine\Common\Cache\MemcacheCache(); | |
self::$driver->setMemcache($memcache); | |
self::$driver->setNamespace($config['resources']['doctrine']['cache']['instances']['memcache']['namespace']); | |
} else { | |
self::$driver = new \Doctrine\Common\Cache\ApcCache(); | |
} | |
return self::$driver; | |
} | |
protected static function _getDriverName() | |
{ | |
$available = array('memcache', 'apc'); | |
foreach ($available as $backend) { | |
if (extension_loaded($backend)) { | |
return $backend; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment