/** * Build menu. * * @param string $alias * @param array $options * @return ItemInterface */ public function get($alias, array $options = []) { $this->assertAlias($alias); if (!array_key_exists($alias, $this->menus)) { if ($this->cache && $this->cache->contains($alias)) { $menuData = $this->cache->fetch($alias); $this->menus[$alias] = $this->factory->createFromArray($menuData); } else { $menu = $this->factory->createItem($alias); /** @var BuilderInterface $builder */ // try to find builder for the specified menu alias if (array_key_exists($alias, $this->builders)) { foreach ($this->builders[$alias] as $builder) { $builder->build($menu, $options, $alias); } } // In any case we must run common builder if (array_key_exists(self::COMMON_BUILDER_ALIAS, $this->builders)) { foreach ($this->builders[self::COMMON_BUILDER_ALIAS] as $builder) { $builder->build($menu, $options, $alias); } } $this->menus[$alias] = $menu; $this->eventDispatcher->dispatch(ConfigureMenuEvent::getEventName($alias), new ConfigureMenuEvent($this->factory, $menu)); $this->sort($menu); if ($this->cache) { $this->cache->save($alias, $menu->toArray()); } } } return $this->menus[$alias]; }
/** * @param string $packageName * @return string */ public function getVersion($packageName = OroPlatformBundle::PACKAGE_NAME) { // Get package version from local cache if any if (isset($this->packageVersions[$packageName])) { return $this->packageVersions[$packageName]; } // Try to get package version from persistent cache if ($this->cache && $this->cache->contains($packageName)) { $version = $this->cache->fetch($packageName); } else { // Get package version from composer repository $packages = $this->factory->getLocalRepository()->findPackages($packageName); if ($package = current($packages)) { /** @var PackageInterface $package */ $version = $package->getPrettyVersion(); } else { $version = self::UNDEFINED_VERSION; } //Save package version to persistent cache if ($this->cache) { $this->cache->save($packageName, $version); } } // Save package version to local cache $this->packageVersions[$packageName] = $version; return $version; }
/** * @return array */ private function loadSettings() { /** @var Setting $setting */ foreach ($this->repository->findAll() as $setting) { $this->cache->save($setting->getKey(), $setting->getValue()); } }
/** * @param string $file * @param \Doctrine\Common\Cache\CacheProvider $cache * @throws \Heystack\Core\Exception\ConfigurationException */ public function __construct($file, CacheProvider $cache) { // if it isn't an absolute path (detected by the file not existing) if (!file_exists($file)) { $file = BASE_PATH . '/' . $file; } if (!file_exists($file)) { throw new ConfigurationException(sprintf("Your file '%s' doesn't exist", $file)); } // Use the contents as the key so invalidation happens on change $key = md5(file_get_contents($file)); if (($config = $cache->fetch($key)) === false) { $config = $this->parseFile($file); $cache->save($key, $config); } if (!is_array($config)) { throw new ConfigurationException(sprintf("Your config is empty for file '%s'", $file)); } if (!array_key_exists('id', $config)) { throw new ConfigurationException(sprintf("Identifier missing for file '%s'", $file)); } if (!array_key_exists('flat', $config)) { throw new ConfigurationException(sprintf("Flat config missing for file '%s'", $file)); } $this->config = $config; }
/** * */ private function clearCache() { $container = $this->getConfigurationPool()->getContainer(); $container->get('harentius_blog.router.category_slug_provider')->clearAll(); $this->cache->deleteAll(); $container->get('harentius_blog.controller.feed_cache')->deleteAll(); }
/** * Removes items from the cache by conditions. * * @param array $conditions * @return void */ public function clean(array $conditions) { if (!isset($conditions[Nette\Caching\Cache::ALL])) { throw new NotImplementedException(); } $this->provider->deleteAll(); }
/** * TCMB sitesi üzerinden XML'i okur. * * @param Curl $curl * * @throws Exception\ConnectionFailed */ private function getTcmbData(Curl $curl = null) { if (is_null($curl)) { $curl = new Curl(); } $curl->setOption(CURLOPT_URL, 'http://www.tcmb.gov.tr/kurlar/today.xml'); $curl->setOption(CURLOPT_HEADER, 0); $curl->setOption(CURLOPT_RETURNTRANSFER, 1); $curl->setOption(CURLOPT_FOLLOWLOCATION, 1); $response = $curl->exec(); if ($response === false) { throw new Exception\ConnectionFailed('Sunucu Bağlantısı Kurulamadı: ' . $curl->error()); } $curl->close(); $this->data = $this->formatTcmbData((array) simplexml_load_string($response)); $timezone = new \DateTimeZone('Europe/Istanbul'); $now = new \DateTime('now', $timezone); $expire = $this->data['today'] == $now->format('d.m.Y') ? 'Tomorrow 15:30' : 'Today 15:30'; $expireDate = new \DateTime($expire, $timezone); $this->data['expire'] = $expireDate->getTimestamp(); if (!is_null($this->cacheDriver)) { $lifetime = $expire - $now->getTimestamp(); // Eğer dosyanın geçerlilik süresi bitmişse veriyi sadece 5 dakika önbellekte tutuyoruz. $this->cacheDriver->save($this->cacheKey, $this->data, $lifetime > 0 ? $lifetime : 300); } }
public function clear() { if (!$this->hasNamespace()) { $this->doctrineCache->flushAll(); } else { $this->withNamespace()->deleteAll(); } }
/** * @param CacheProvider $cacheProvider * * @return CacheProvider */ protected function decorateWithConnectable(CacheProvider $cacheProvider) { $memcached = $this->getMemcachedAdapter(); $settings = $this->config->getSettings(); $memcached->addserver($settings['host'], $settings['port']); $cacheProvider->setMemcached($memcached); return $cacheProvider; }
/** * (non-PHPdoc) * @see Generator/Admingenerator\GeneratorBundle\Generator.GeneratorInterface::build() */ public function build() { if ($this->cacheProvider->fetch($this->getCacheKey())) { return; } $this->doBuild(); $this->cacheProvider->save($this->getCacheKey(), true); }
protected function clearCacheDriver(CacheProvider $cacheDriver = null, $description = "") { if ($cacheDriver !== null) { $this->output .= 'Doctrine ' . $description . ' cache: ' . $cacheDriver->getNamespace() . ' — '; $this->output .= $cacheDriver->deleteAll() ? '<info>OK</info>' : '<info>FAIL</info>'; $this->output .= PHP_EOL; } }
/** * @param CacheProvider $cacheProvider * * @return CacheProvider */ protected function decorateWithConnectable(CacheProvider $cacheProvider) { $redis = $this->getRedisAdapter(); $settings = $this->config->getSettings(); $redis->connect($settings['host'], $settings['port']); $cacheProvider->setRedis($redis); return $cacheProvider; }
/** * @param string $packageName * * @return int */ protected function getCachedAssetVersion($packageName) { if (!array_key_exists($packageName, $this->localCache)) { $version = $this->cache->fetch($packageName); $this->localCache[$packageName] = false !== $version ? $version : 0; } return $this->localCache[$packageName]; }
/** * @test */ public function FetchWithNamespace_StoreInformation() { $this->cacheProvider->save('namespaceId', 'namespace_id'); $this->cacheProvider->save('namespace_idid', 'data-test'); $this->decorator->fetchWithNamespace('id', 'namespaceId'); $this->decorator->fetchWithNamespace('id', 'namespaceId'); $this->assertCollectedData([new FetchWithNamespaceCacheCollectedData('id', 'namespaceId', 'data-test', 0)], $this->decorator->getCollectedData()); }
/** * Constructor * * $injector function () {return Injector::create([new Module])}; * $initialization function ($instance, InjectorInterface $injector) {}; * * @param callable $injector * @param callable $initialization * @param string $cacheNamespace * @param CacheProvider $cache * @param ClassLoaderInterface $classLoader */ public function __construct(callable $injector, callable $initialization, $cacheNamespace, CacheProvider $cache, ClassLoaderInterface $classLoader = null) { $this->injector = $injector; $this->initialization = $initialization; $this->cacheNamespace = $cacheNamespace; $this->cache = $cache; $cache->setNamespace($cacheNamespace); $this->cache = $cache; $this->classLoader = $classLoader ?: new AopClassLoader(); }
/** * {@inheritdoc} */ public function get(RequesterInterface $requester, ResourceInterface $resource) { $cacheId = $this->getCacheId($requester, $resource); $permission = $this->cacheProvider->fetch($cacheId); if ($permission instanceof PermissionInterface) { return $permission; } $this->cacheProvider->delete($cacheId); return; }
/** * Renews the timestamp of the last update of database translations for the given locale * * @param string|null $locale */ public function updateTimestamp($locale = null) { if ($locale) { $this->localCache[$locale] = (new \DateTime('now', new \DateTimeZone('UTC')))->getTimestamp(); $this->cacheImpl->save($locale, $this->localCache[$locale]); } else { $this->localCache = []; $this->cacheImpl->deleteAll(); } }
/** * {@inheritdoc} */ public function canReblog($post) { $cacheKey = $this->makeCacheKey($post); $cached = $this->cache->fetch($cacheKey); if ($cached) { return false; } $this->cache->save($cacheKey, '1', $this->term); return true; }
/** * Initialize MetadataCollector. */ public function setUp() { $this->docLocator = $this->getMockBuilder('Sineflow\\ElasticsearchBundle\\Mapping\\DocumentLocator')->disableOriginalConstructor()->getMock(); $this->docLocator->method('getShortClassName')->willReturnArgument(0); $this->docParser = $this->getMockBuilder('Sineflow\\ElasticsearchBundle\\Mapping\\DocumentParser')->disableOriginalConstructor()->getMock(); $this->cache = $this->getMockBuilder('Doctrine\\Common\\Cache\\FilesystemCache')->disableOriginalConstructor()->getMock(); $metadata = new DocumentMetadata(array('type' => 'foo', 'properties' => array('title' => array('null_value' => false, 'type' => 'boolean'), '_id' => array('type' => 'string'), '_score' => array('type' => 'float'), '_parent' => array('type' => 'string')), 'fields' => array('_all' => array('enabled' => true)), 'propertiesMetadata' => array('title' => array('propertyName' => 'title', 'type' => 'boolean', 'multilanguage' => null, 'propertyAccess' => 1), '_id' => array('propertyName' => 'id', 'type' => 'string', 'multilanguage' => null, 'propertyAccess' => 1), '_score' => array('propertyName' => 'score', 'type' => 'float', 'multilanguage' => null, 'propertyAccess' => 1), '_parent' => array('propertyName' => 'parent', 'type' => 'string', 'multilanguage' => null, 'propertyAccess' => 1)), 'objects' => array(0 => 'AppBundle\\ElasticSearch\\Document\\ObjSome', 1 => 'AppBundle\\ElasticSearch\\Document\\ObjOther'), 'repositoryClass' => null, 'className' => 'AppBundle\\ElasticSearch\\Document\\Foo', 'shortClassName' => 'TestBundle:Foo')); $this->cache->method('fetch')->willReturn(['foo' => ['TestBundle:Foo' => $metadata]]); $indexManagers = ['test' => ['name' => 'testname', 'connection' => 'test1', 'use_aliases' => false, 'settings' => ['refresh_interval' => 2, 'number_of_replicas' => 3, 'analysis' => ['filter' => ['test_filter' => ['type' => 'nGram']], 'tokenizer' => ['test_tokenizer' => ['type' => 'nGram']], 'analyzer' => ['test_analyzer' => ['type' => 'custom']]]], 'types' => ['TestBundle:Foo', 'TestBundle:Bar']]]; $this->metadataCollector = new DocumentMetadataCollector($indexManagers, $this->docLocator, $this->docParser, $this->cache); }
/** * Loads tree data and save them in cache */ protected function loadTree() { $treeData = new OwnerTree(); if ($this->checkDatabase()) { $this->fillTree($treeData); } if ($this->cache) { $this->cache->save(self::CACHE_KEY, $treeData); } $this->tree = $treeData; }
public function saveCollectInformation($id, $information) { $this->cache->save($id, $information); $indexArray = $this->cache->fetch('index'); if (empty($indexArray)) { $indexArray = []; } $indexArray[$id] = array_merge($information['request'], $information['response']); $this->cache->save('index', $indexArray); return $id; }
/** * Finds first available image for listing purposes * * @param Content $content * * @return string */ public function getCoverImage(Content $content) { $key = $content->getCoverImageCacheKey(); if (!($image = $this->cache->fetch($key))) { $image = $content->getCoverImage(); if ($image) { $image = $this->imageCacheManager->getBrowserPath($image, 'medialibrary'); } $this->cache->save($key, $image, 86400); } return $image; }
public function call() { if (!in_array($this->app->request()->getMethod(), ['GET', 'HEAD'])) { return $this->next->call(); } $cacheKey = $this->app->request()->getPathInfo(); if ($this->cache->contains($cacheKey)) { $resource = $this->cache->fetch($cacheKey); $lastModified = strtotime($resource['last_updated_at']); $this->app->lastModified($lastModified); } $this->next->call(); }
protected function setUp() { $this->cache = $this->getMockForAbstractClass('Doctrine\\Common\\Cache\\CacheProvider'); $this->cache->expects($this->any())->method('fetch')->will($this->returnValue(false)); $this->cache->expects($this->any())->method('save'); $this->ownershipMetadataProvider = $this->getMockBuilder('OroB2B\\Bundle\\CustomerBundle\\Owner\\Metadata\\FrontendOwnershipMetadataProvider')->disableOriginalConstructor()->getMock(); $this->managerRegistry = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry'); $this->securityFacade = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\SecurityFacade')->disableOriginalConstructor()->getMock(); $this->container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $this->container->expects($this->any())->method('get')->willReturnMap([['orob2b_customer.owner.frontend_ownership_tree_provider.cache', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->cache], ['orob2b_customer.owner.frontend_ownership_metadata_provider', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->ownershipMetadataProvider], ['doctrine', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->managerRegistry], ['oro_security.security_facade', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->securityFacade]]); $this->treeProvider = new FrontendOwnerTreeProvider(); $this->treeProvider->setContainer($this->container); }
/** * @return string */ public function get() { $key = 'feed'; if ($this->cache->contains($key)) { return $this->cache->fetch($key); } $articles = $this->articleRepository->findPublishedOrderedByPublishDate(); $feed = $this->feedManager->get('article'); $feed->addFromArray($articles); $renderedFeed = $feed->render('rss'); $this->cache->save($key, $renderedFeed); return $renderedFeed; }
/** * @param CacheProvider $cacheProvider */ public function setCacheProvider($cacheProvider) { $namespace = '[<>]' . rtrim($this->getName() . '|' . $cacheProvider->getNamespace(), '|') . '[<>]'; $arrayCache = new ArrayCache(); $cacheChain = new ChainCache([$arrayCache, $cacheProvider]); $cacheProvider = new Wrapper($cacheChain); $cacheProvider->setNamespace($namespace); $this->cacheProvider = $cacheProvider; $this->readConnection->setCacheProvider($cacheProvider); if ($this->writeConnection) { $this->writeConnection->setCacheProvider($cacheProvider); } }
/** * Fetches piece of JS-code with require.js main config from cache * or if it was not there - generates and put into a cache * * @return string */ public function getMainConfig() { $config = null; if ($this->cache) { $config = $this->cache->fetch(self::REQUIREJS_CONFIG_CACHE_KEY); } if (empty($config)) { $config = $this->generateMainConfig(); if ($this->cache) { $this->cache->save(self::REQUIREJS_CONFIG_CACHE_KEY, $config); } } return $config; }
protected function setUp() { $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $managerRegistry = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry'); $managerRegistry->expects($this->any())->method('getManagerForClass')->willReturn($this->em); $this->cache = $this->getMockForAbstractClass('Doctrine\\Common\\Cache\\CacheProvider'); $this->cache->expects($this->any())->method('fetch')->will($this->returnValue(false)); $this->cache->expects($this->any())->method('save'); $this->securityFacade = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\SecurityFacade')->disableOriginalConstructor()->getMock(); $this->container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $this->container->expects($this->any())->method('get')->will($this->returnValueMap([['oro_security.ownership_tree_provider.cache', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->cache], ['oro_security.owner.ownership_metadata_provider', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, new OwnershipMetadataProviderStub($this, ['user' => 'Oro\\Bundle\\UserBundle\\Entity\\User', 'business_unit' => 'Oro\\Bundle\\OrganizationBundle\\Entity\\BusinessUnit'])], ['doctrine', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $managerRegistry], ['oro_security.security_facade', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->securityFacade]])); $this->treeProvider = new OwnerTreeProvider($this->em, $this->cache); $this->treeProvider->setContainer($this->container); }
/** * @return array */ public function getAll() { $key = 'statistics'; if ($this->cache->contains($key)) { return $this->cache->fetch($key); } $statistics = $this->articleRepository->findStatistics(); $mostPopularArticle = $this->articleRepository->findMostPopular(); if ($mostPopularArticle) { $statistics['mostPopularArticleData'] = ['slug' => $mostPopularArticle->getSlug(), 'title' => $mostPopularArticle->getTitle(), 'viewsCount' => $mostPopularArticle->getViewsCount()]; } $this->cache->save($key, $statistics, $this->cacheLifetime); return $statistics; }
public function checkDeploy(GetResponseEvent $event) { if (null === $this->cache || $this->cache->contains(self::CHECK_DEPLOY_KEY)) { return; } $clients = $this->clientRepository->countClients(); $cities = $this->cityRepository->countCities(); $hasDefaultClient = $this->clientRepository->findOneByUid($this->defaultClientUid) instanceof Client; if ($clients <= 0 || $cities <= 0 || !$hasDefaultClient) { $this->cache->delete(self::CHECK_DEPLOY_KEY); throw new \RuntimeException('Make sure you did run the populate database command.'); } else { $this->cache->save(self::CHECK_DEPLOY_KEY, true); } }