Created
March 6, 2012 17:47
-
-
Save peterjmit/1987713 to your computer and use it in GitHub Desktop.
Get the Result Cache from the doctrine entity manager
This file contains hidden or 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 | |
class Foo | |
{ | |
private $_em; | |
public function __construct($entity_manager) | |
{ | |
$this->_em = $entityManager; | |
} | |
/** | |
* I couldn't find any where in the Doctrine or Symfony docs that explained | |
* how to get the Cache Driver defined in my config_prod.yml file for use | |
* in saving custom arrays/keys. | |
* | |
* (Rather than directly instantiating a cache driver i.e. $cacheDriver = new \Doctrine\Common\Cache\ApcCache()) | |
* | |
* @return Implementation of Doctrine\Common\Cache\Cache (APC/Xcache etc.) | |
*/ | |
public function getCacheDriver() | |
{ | |
return $this->_em->getConfiguration()->getResultCacheImpl(); | |
} | |
/** | |
* Example usage of Foo::getCacheDriver | |
* | |
*/ | |
public function saveToCache($item_to_save) | |
{ | |
$this->getCacheDriver()->save('foo_key', $item_to_save); | |
} | |
} | |
$foo = new Foo($doctrine_entity_manager); | |
$foo->saveToCache('bar'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment