public function clearCacheSection($block_id, $section_id) { $fullCode = $this->getFullCode($section_id); $cacheDriver = new \Doctrine\Common\Cache\ApcCache(); $nameSpace = 'SectionAction_dev_' . $block_id; $cacheDriver->setNamespace($nameSpace); $cacheDriver->delete($fullCode); $nameSpace = 'SectionAction_prod_' . $block_id; $cacheDriver->setNamespace($nameSpace); $cacheDriver->delete($fullCode); }
private function getCacheDriver() { //$redis = new Redis(); //$redis->connect('127.0.0.1', 6379); $site = $this->getSite(); //$env = $this->get('kernel')->getEnvironment(); $env = 'test'; //$cacheDriver = new \Doctrine\Common\Cache\FilesystemCache($_SERVER['DOCUMENT_ROOT'] . '/../app/cache/' . $env . '/sys/' . $site['id'] . '/pages/'); $cacheDriver = new \Doctrine\Common\Cache\ApcCache(); //$cacheDriver = new \Doctrine\Common\Cache\RedisCache(); $cacheDriver->setNamespace('Pages_' . $env); return $cacheDriver; }
/** * * 获取缓存信息 * @return \Doctrine\Common\Cache\MongoDBCache */ protected function getCache() { $namespace = 'PanGuKTD_ORM_'; $cacheConfig = config('doctrine'); $cacheName = $cacheConfig['name']; $cache = null; if ($cacheName == 'array') { $cache = new \Doctrine\Common\Cache\ArrayCache(); } elseif ($cacheName == 'xcache') { $cache = new \Doctrine\Common\Cache\XcacheCache(); } elseif ($cacheName == 'memcached') { $memcached = new \Memcached(); $memcached->addServers($cacheConfig['memcached']); $cache = new \Doctrine\Common\Cache\MemcachedCache(); $cache->setMemcached($memcached); $cache->setNamespace($namespace); } elseif ($cacheName == 'memcache') { $memcache = new \Memcache(); foreach ($cacheConfig['memcache'] as $key => $value) { $memcache->addServer($value['host'], $value['port'], $value['persistent'], $value['weight']); } $cache = new \Doctrine\Common\Cache\MemcacheCache(); $cache->setMemcache($memcache); $cache->setNamespace($namespace); } elseif ($cacheName == 'apc') { $cache = new \Doctrine\Common\Cache\ApcCache(); $cache->setNamespace($namespace); } elseif ($cacheName == 'mongo') { $host = $cacheConfig['mongo']['host']; $port = $cacheConfig['mongo']['port']; $opt = $cacheConfig['mongo']['options']; $mongo = new \MongoClient("mongodb://{$host}:{$port}", $opt); $mongo = new \MongoDB($mongo, 'doctrine_orm_cache'); $conn = new \MongoCollection($mongo, $namespace); $cache = new \Doctrine\Common\Cache\MongoDBCache($conn); $cache->setNamespace($namespace); } elseif ($cacheName == 'redis') { $host = $cacheConfig['redis']['host']; $port = $cacheConfig['redis']['port']; $redis = new \Redis(); $redis->connect($host, $port); $cache = new \Doctrine\Common\Cache\RedisCache(); $cache->setRedis($redis); } return $cache; }
/** * * @return \Doctrine\ORM\EntityManager */ private static function getEntityManager() { $sbConfig = new \Sb\Config\Model\Config(); $cache = new \Doctrine\Common\Cache\ApcCache(); $cache->setNamespace($sbConfig->getApcCacheNamespace()); $config = new \Doctrine\ORM\Configuration(); $driverImpl = $config->newDefaultAnnotationDriver(array("/Sb/Db/Model")); $config->setMetadataDriverImpl($driverImpl); // settings caches $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $config->setResultCacheImpl($cache); $config->setProxyDir("Sb/Db/Proxies"); $config->setProxyNamespace('Proxies'); $config->setAutoGenerateProxyClasses(false); $connectionOptions = array('driver' => 'pdo_mysql', 'user' => $sbConfig->getDatabaseParams()->user, 'password' => $sbConfig->getDatabaseParams()->password, 'host' => $sbConfig->getDatabaseParams()->host, 'dbname' => $sbConfig->getDatabaseParams()->name); // Create EntityManager $entityManager = \Doctrine\ORM\EntityManager::create($connectionOptions, $config); $entityManager->getEventManager()->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit('utf8', 'utf8_general_ci')); return $entityManager; }
public function __call($method, $args) { $driver = null; switch (config()->cache_driver()) { case 'memcached': $memcached = new \Memcached(); $memcached->addServer(config()->cache_host(), 11211); $driver = new \Doctrine\Common\Cache\MemcachedCache(); $driver->setMemcached($memcached); break; case 'apc': $driver = new \Doctrine\Common\Cache\ApcCache(); break; } switch ($method) { case 'set': // $driver->delete($args[0]); $driver->save($args[0], json_encode($args[1])); break; case 'get': return json_decode($driver->fetch($args[0])); break; } }
/** * Detects the correct doctrine cache driver for the user caching engine in use * @return \Doctrine\Common\Cache\AbstractCache The doctrine cache driver object */ public function getDoctrineCacheDriver() { if ($this->doctrineCacheEngine) { // return cache engine if already set return $this->doctrineCacheEngine; } $userCacheEngine = $this->getUserCacheEngine(); // check if user caching is active if (!$this->getUserCacheActive()) { $userCacheEngine = \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_OFF; } switch ($userCacheEngine) { case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_APC: $cache = new \Doctrine\Common\Cache\ApcCache(); $cache->setNamespace($this->getCachePrefix()); break; case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_MEMCACHE: $memcache = $this->getMemcache(); $cache = new \Doctrine\Common\Cache\MemcacheCache(); $cache->setMemcache($memcache); $cache->setNamespace($this->getCachePrefix()); break; case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_MEMCACHED: $memcached = $this->getMemcached(); $cache = new \Doctrine\Common\Cache\MemcachedCache(); $cache->setMemcached($memcached); $cache->setNamespace($this->getCachePrefix()); break; case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_XCACHE: $cache = new \Doctrine\Common\Cache\XcacheCache(); $cache->setNamespace($this->getCachePrefix()); break; case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_FILESYSTEM: $cache = new \Cx\Core_Modules\Cache\Controller\Doctrine\CacheDriver\FileSystemCache($this->strCachePath); break; default: $cache = new \Doctrine\Common\Cache\ArrayCache(); break; } // set the doctrine cache engine to avoid getting it a second time $this->doctrineCacheEngine = $cache; return $cache; }
private function clearMenuCache($menu_id) { //$env = $this->container->getParameter("kernel.environment"); //echo '<pre>' . print_r('Удаление кеша '.$menu_id, true) . '</pre>'; exit; $cacheDriver = new \Doctrine\Common\Cache\ApcCache(); $cacheDriver->setNamespace('menu_prod_' . $menu_id); $cacheDriver->deleteAll(); $cacheDriver->setNamespace('menu_dev_' . $menu_id); $cacheDriver->deleteAll(); }
/** * Gets the 'doctrine.orm.default_entity_manager' service. * * This service is shared. * This method always returns the same instance of the service. * * @return Doctrine\ORM\EntityManager A Doctrine\ORM\EntityManager instance. */ protected function getDoctrine_Orm_DefaultEntityManagerService() { $a = new \Doctrine\Common\Cache\ApcCache(); $a->setNamespace('sf2orm_default_28fbb686b577c74454a442d0c7af15b4'); $b = new \Doctrine\Common\Cache\ApcCache(); $b->setNamespace('sf2orm_default_28fbb686b577c74454a442d0c7af15b4'); $c = new \Doctrine\Common\Cache\ApcCache(); $c->setNamespace('sf2orm_default_28fbb686b577c74454a442d0c7af15b4'); $d = new \Doctrine\ORM\Mapping\Driver\DriverChain(); $d->addDriver(new \Doctrine\ORM\Mapping\Driver\AnnotationDriver(new \Symfony\Bridge\Doctrine\Annotations\IndexedReader($this->get('annotation_reader')), array(0 => '/home/vamps/sfprojects/Exigency/src/Pasa/RequirementBundle/Entity')), 'Pasa\\RequirementBundle\\Entity'); $e = new \Doctrine\ORM\Configuration(); $e->setEntityNamespaces(array('PasaRequirementBundle' => 'Pasa\\RequirementBundle\\Entity')); $e->setMetadataCacheImpl($a); $e->setQueryCacheImpl($b); $e->setResultCacheImpl($c); $e->setMetadataDriverImpl($d); $e->setProxyDir('/home/vamps/sfprojects/Exigency/app/cache/prod/doctrine/orm/Proxies'); $e->setProxyNamespace('Proxies'); $e->setAutoGenerateProxyClasses(true); $e->setClassMetadataFactoryName('Doctrine\\ORM\\Mapping\\ClassMetadataFactory'); return $this->services['doctrine.orm.default_entity_manager'] = call_user_func(array('Doctrine\\ORM\\EntityManager', 'create'), $this->get('doctrine.dbal.default_connection'), $e); }
public function render($options) { $time_start = microtime(1); $request = $this->container->get('request'); $env = $this->container->getParameter("kernel.environment"); $routeParams = $request->get('_route_params'); $options['@request_uri'] = $_SERVER['REQUEST_URI']; $cacheId = json_encode($options); //$cacheDriver = new \Doctrine\Common\Cache\FilesystemCache($_SERVER['DOCUMENT_ROOT'] . '/../app/cache/' . $env . '/sys/menu/'); $cacheDriver = new \Doctrine\Common\Cache\ApcCache(); $namespace = 'menu_' . $env . '_' . $options['id']; $this->logger->info('Menu ' . $options['id'] . ' NameSpace: ' . $namespace); $cacheDriver->setNamespace($namespace); if ($fooString = $cacheDriver->fetch($cacheId)) { $result = unserialize($fooString); } else { $array = $this->getArray($options['id']); $result = $this->getMenu($options, $array); $cacheDriver->save($cacheId, serialize($result)); } echo $result; $time_end = microtime(1); $time = number_format(($time_end - $time_start) * 1000, 2); //echo $time.' мс'; }
private function clearCache($page_id) { $cacheDriver = new \Doctrine\Common\Cache\ApcCache(); $cacheDriver->delete('page_' . $page_id); }
private function clearElementsListCache($request, $block_id) { $env = $this->get('kernel')->getEnvironment(); $cacheDriver = new \Doctrine\Common\Cache\ApcCache(); $cacheDriver->setNamespace('ElementsListAction_' . $env . '_' . $block_id); $cacheDriver->deleteAll(); }
/** * Returns the doctrine entity manager * @return \Doctrine\ORM\EntityManager */ public function getEntityManager() { if ($this->em) { return $this->em; } global $objCache; $config = new \Doctrine\ORM\Configuration(); $userCacheEngine = $objCache->getUserCacheEngine(); if (!$objCache->getUserCacheActive()) { $userCacheEngine = \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_OFF; } $arrayCache = new \Doctrine\Common\Cache\ArrayCache(); switch ($userCacheEngine) { case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_APC: $cache = new \Doctrine\Common\Cache\ApcCache(); $cache->setNamespace($this->db->getName() . '.' . $this->db->getTablePrefix()); break; case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_MEMCACHE: $memcache = $objCache->getMemcache(); if ($memcache instanceof \Memcache) { $cache = new \Doctrine\Common\Cache\MemcacheCache(); $cache->setMemcache($memcache); } elseif ($memcache instanceof \Memcached) { $cache = new \Doctrine\Common\Cache\MemcachedCache(); $cache->setMemcache($memcache); } $cache->setNamespace($this->db->getName() . '.' . $this->db->getTablePrefix()); break; case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_XCACHE: $cache = new \Doctrine\Common\Cache\XcacheCache(); $cache->setNamespace($this->db->getName() . '.' . $this->db->getTablePrefix()); break; case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_FILESYSTEM: $cache = new \Cx\Core_Modules\Cache\Controller\Doctrine\CacheDriver\FileSystemCache(ASCMS_CACHE_PATH); break; default: $cache = $arrayCache; break; } \Env::set('cache', $cache); //$config->setResultCacheImpl($cache); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $config->setProxyDir(ASCMS_MODEL_PROXIES_PATH); $config->setProxyNamespace('Cx\\Model\\Proxies'); /** * This should be set to true if workbench is present and active. * Just checking for workbench.config is not really a good solution. * Since ConfigurationFactory used by EM caches auto generation * config value, there's no possibility to set this later. */ $config->setAutoGenerateProxyClasses(file_exists(ASCMS_DOCUMENT_ROOT . '/workbench.config')); $connectionOptions = array('pdo' => $this->getPdoConnection(), 'dbname' => $this->db->getName()); $evm = new \Doctrine\Common\EventManager(); $chainDriverImpl = new \Doctrine\ORM\Mapping\Driver\DriverChain(); $driverImpl = new \Cx\Core\Model\Controller\YamlDriver(array(ASCMS_CORE_PATH . '/Core' . '/Model/Yaml')); $chainDriverImpl->addDriver($driverImpl, 'Cx'); //loggable stuff $loggableDriverImpl = $config->newDefaultAnnotationDriver(ASCMS_LIBRARY_PATH . '/doctrine/Gedmo/Loggable/Entity'); $chainDriverImpl->addDriver($loggableDriverImpl, 'Gedmo\\Loggable'); $this->loggableListener = new \Cx\Core\Model\Model\Event\LoggableListener(); $this->loggableListener->setUsername('currently_loggedin_user'); // in real world app the username should be loaded from session, example: // Session::getInstance()->read('user')->getUsername(); $evm->addEventSubscriber($this->loggableListener); //tree stuff $treeListener = new \Gedmo\Tree\TreeListener(); $evm->addEventSubscriber($treeListener); $config->setMetadataDriverImpl($chainDriverImpl); //table prefix $prefixListener = new \DoctrineExtension\TablePrefixListener($this->db->getTablePrefix()); $evm->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $prefixListener); $config->setSqlLogger(new \Cx\Lib\DBG\DoctrineSQLLogger()); $em = \Cx\Core\Model\Controller\EntityManager::create($connectionOptions, $config, $evm); //resolve enum, set errors $conn = $em->getConnection(); $conn->setCharset($this->db->getCharset()); $conn->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); $conn->getDatabasePlatform()->registerDoctrineTypeMapping('set', 'string'); $this->em = $em; return $this->em; }
public function sections_listAction($block_id = false, $section_id = null, $template_code = "default", $get_elements = null, $params) { //$cache = new \Doctrine\Common\Cache\FilesystemCache($_SERVER['DOCUMENT_ROOT'] . '/../app/cache/sys/components/sections_list/'); $cache = new \Doctrine\Common\Cache\ApcCache(); $cacheId = md5(json_encode(array('block_id' => $block_id, 'section_id' => $section_id, 'template_code' => $template_code, 'get_elements' => $get_elements))); //echo '<pre>' . print_r($cache->fetch($cacheId), true) . '</pre>'; if ($fooString = $cache->fetch($cacheId)) { //echo '<pre>' . print_r('возвращаем закешированные данные', true) . '</pre>'; $render = unserialize($fooString); } else { //echo '<pre>' . print_r('возвращаем не закешированные данные', true) . '</pre>'; $em = $this->getDoctrine()->getManager(); //echo '<pre>' . print_r($block_id, true) . '</pre>'; if (is_numeric($block_id)) { //$sections = $em->getRepository('NovuscomCMFBundle:Section')->findBy(array('block' => $block_id, 'lvl' => 0)); //echo '<pre>' . print_r($block_id, true) . '</pre>'; $repository = $em->getRepository('NovuscomCMFBundle:Section'); $query = $repository->createQueryBuilder('p')->where('p.block = :block_id')->setParameters(array('block_id' => $block_id))->orderBy('p.sort', 'ASC')->getQuery(); $sections = $query->getResult(); /*foreach($sections as $s) { echo '<pre>' . print_r($s->getName(), true) . '</pre>'; }*/ } else { //echo '<pre>' . print_r('notfound', true) . '</pre>'; throw $this->createNotFoundException(''); } if (is_int($section_id)) { $repository = $em->getRepository('NovuscomCMFBundle:Section'); $query = $repository->createQueryBuilder('p')->where('p.id = :section_id')->setParameter('section_id', $section_id)->orderBy('p.sort', 'ASC')->getQuery(); $sections = $query->getResult(); } $this->setSectionsElements($sections); $response = new Response(); $data = array(); $data['sections'] = $sections; //echo '<pre>' . print_r($template_code, true) . '</pre>'; $render = $this->render('@templates/' . $params['params']['template_directory'] . '/SectionsList/' . $template_code . '.html.twig', $data, $response); } return $render; }
public function ElementsListAction($params, Request $request) { if ($this->checkConstruction()) { return $this->constructionResponse(); } /** * Переменные */ $response = new Response(); $em = $this->getDoctrine()->getManager(); $page_repository = $em->getRepository('NovuscomCMFBundle:Page'); $host = $request->headers->get('host'); $cacheId = json_encode($params); $section_id = null; if (array_key_exists('section_id', $params)) { $section_id = $params['section_id']; } $template_code = 'default'; if (array_key_exists('template_code', $params)) { $template_code = $params['template_code']; } $env = $this->get('kernel')->getEnvironment(); $exist_page_id = array_key_exists('page_id', $params); if (!$exist_page_id) { $params['page_id'] = false; } if (!array_key_exists('LIMIT', $params)) { $params['LIMIT'] = null; } if (!array_key_exists('OPTIONS', $params)) { $params['OPTIONS'] = null; } /** * Кэш */ //$cacheDriver = new \Doctrine\Common\Cache\FilesystemCache($_SERVER['DOCUMENT_ROOT'] . '/../app/cache/' . $env . '/sys/' . $host . '/components/ElementsList/'); $cacheDriver = new \Doctrine\Common\Cache\ApcCache(); $cacheDriver->setNamespace('ElementsListAction_' . $env . '_' . $params['BLOCK_ID']); //if (false) { if ($fooString = $cacheDriver->fetch($cacheId)) { //echo '<pre>' . print_r('есть такое в кеше', true) . '</pre>'; $render = unserialize($fooString); } else { $response_data = array(); //echo '<pre>' . print_r($params, true) . '</pre>'; /** * Элементы */ $ElementsList = $this->get('ElementsList'); $ElementsList->setBlockId($params['BLOCK_ID']); $ElementsList->setSelect(array('code', 'last_modified', 'preview_picture', 'preview_text')); // TODO Здесь в сервисе ElementList - выбирать все свойства $ElementsList->selectProperties(array('address', 'shirota', 'anounce', 'long_name', 'date')); $ElementsList->setFilter(array('active' => true)); $ElementsList->setLimit($params['LIMIT']); $ElementsList->setOrder(array('name', 'asc')); $elements = $ElementsList->getResult(); /** * Данные попадающие в шаблон */ $response_data['elements'] = $elements; $response_data['options'] = $params['OPTIONS']; $response_data['page'] = $page_repository->find($params['page_id']); $render = $this->render('@templates/' . $params['params']['template_directory'] . '/ElementsList/' . $template_code . '.html.twig', $response_data, $response); $cacheDriver->save($cacheId, serialize($render)); } return $render; }
/** * Gets the 'doctrine_cache.providers.doctrine.orm.default_query_cache' service. * * This service is shared. * This method always returns the same instance of the service. * * @return \Doctrine\Common\Cache\ApcCache A Doctrine\Common\Cache\ApcCache instance. */ protected function getDoctrineCache_Providers_Doctrine_Orm_DefaultQueryCacheService() { $this->services['doctrine_cache.providers.doctrine.orm.default_query_cache'] = $instance = new \Doctrine\Common\Cache\ApcCache(); $instance->setNamespace('sf2orm_default_1fbe33faaa7042c488ae0c8944a56537c8477040ec290926942e6feafea35016'); return $instance; }