umm… silly question.
I know that one can (and should) use APC cache driver with Doctrine ORM.
But I was just wondering if I can also cache entity manager instance itself?
Is there anything that prevents me from doing this:
$em = apc_fetch('em');
if(!$em){
$cache = new Doctrine\Common\Cache\ApcCache;
$config = new Doctrine\ORM\Configuration;
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
$config->setAutoGenerateProxyClasses(TRUE);
$config->setProxyNamespace('MyProject\Proxies');
$config->setProxyDir(APP_PATH . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'proxy');
$driverImpl = $config->newDefaultAnnotationDriver('/path/to/lib/MyProject/Entities');
$config->setMetadataDriverImpl($driverImpl);
$connectionOptions = array(
'driver' => 'pdo_sqlite',
'path' => 'database.sqlite'
);
$em = Doctrine\ORM\EntityManager::create($connectionOptions, $config);
apc_store('em', $em);
}
Your code should work just fine.
Actually we also do cache EM in our projects. Saves some 300Kb:)