contains() public method

public contains ( $id )
コード例 #1
0
 /**
  * @param string $key
  * @return mixed|null
  */
 public function get($key)
 {
     if (!$this->cache->contains($key)) {
         $this->loadSettings();
     }
     return $this->cache->fetch($key);
 }
コード例 #2
0
ファイル: VersionHelper.php プロジェクト: Maksold/platform
 /**
  * @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;
 }
コード例 #3
0
 /**
  * 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];
 }
コード例 #4
0
ファイル: Rating.php プロジェクト: harentius/blog-bundle
 /**
  * @param Article $article
  * @return bool
  */
 public function isRated(Article $article)
 {
     $ip = $this->getRequest()->getClientIp();
     if ($this->cache->contains($ip)) {
         return true;
     }
     return $this->isLiked($article) || $this->isDisLiked($article);
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 public function deleteItems(array $keys)
 {
     foreach ($keys as $key) {
         if (true === $this->provider->contains($key)) {
             $this->provider->delete($key);
         }
     }
     return $this;
 }
コード例 #6
0
ファイル: Doviz.php プロジェクト: teknomavi/tcmb
 /**
  * @param \Doctrine\Common\Cache\CacheProvider $cacheDriver
  */
 public function __construct($cacheDriver = null)
 {
     if (!is_null($cacheDriver) && class_exists('\\Doctrine\\Common\\Cache\\CacheProvider')) {
         if ($cacheDriver instanceof \Doctrine\Common\Cache\CacheProvider) {
             $this->cacheDriver = $cacheDriver;
             if ($this->cacheDriver->contains($this->cacheKey)) {
                 $this->data = $this->cacheDriver->fetch($this->cacheKey);
             }
         }
     }
 }
コード例 #7
0
 /**
  * @param EventInterface $event
  */
 public function preFind(EventInterface $event)
 {
     if (!preg_match('/\\d$/', $this->cacheId)) {
         return;
         //The current route is a POST, do not cache new resources with this cache ID
     }
     if ($this->cache->contains($this->cacheId)) {
         $event->stopPropagation(true);
         return $this->cache->fetch($this->cacheId);
     }
 }
コード例 #8
0
 /**
  * @return array
  */
 public function loadSourceData()
 {
     if (null === $this->cache) {
         return $this->formatDataLoader->load($this->getUrl());
     }
     $key = $this->getObjectKey();
     if (!$this->cache->contains($key)) {
         $this->cache->save($key, $this->formatDataLoader->load($this->getUrl()), $this->getTtl());
     }
     return $this->cache->fetch($key);
 }
コード例 #9
0
 public function testInvalidate()
 {
     $key = 'test';
     // create a fake list
     $this->cache->register($key, uniqid());
     $this->cache->register($key, uniqid());
     $this->ormCache->save($key, 'bar');
     $this->cache->invalidate($key);
     // now both the orm cache and our cache should not contain this list
     $this->assertFalse($this->ormCache->contains($key));
     $this->assertNotContains($key, $this->cache->getRegisteredKeys($key));
 }
コード例 #10
0
 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();
 }
コード例 #11
0
ファイル: Feed.php プロジェクト: harentius/blog-bundle
 /**
  * @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;
 }
コード例 #12
0
ファイル: Statistics.php プロジェクト: harentius/blog-bundle
 /**
  * @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;
 }
コード例 #13
0
 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);
     }
 }
コード例 #14
0
 /**
  *
  * @param string $name
  * @param string $processor
  * @param \Heyday\CacheInclude\KeyCreators\KeyCreatorInterface $keyCreator
  * @throws \InvalidArgumentException
  * @return mixed
  */
 public function process($name, $processor, KeyCreatorInterface $keyCreator)
 {
     if (!$processor instanceof ProcessorInterface && !is_callable($processor)) {
         throw new \InvalidArgumentException('The argument $processor must be an instance of ProcessorInterface or a callable');
     }
     if (!$this->enabled) {
         return $processor($name);
     }
     $config = $this->getCombinedConfig($name);
     $key = $this->getKey($name, $keyCreator, $config);
     if ($this->forceExpire) {
         $this->cache->delete($key);
         $this->removeStoredKey($name, $key);
         $result = $processor($name);
         $type = "EXPIRE";
     } elseif ($this->cache->contains($key)) {
         $result = $this->cache->fetch($key);
         $type = "HIT";
     } else {
         $this->cache->save($key, $result = $processor($name), $this->getExpiry($config));
         $this->addStoredKey($name, $key, $keyCreator);
         $type = "MISS";
     }
     $this->log($type, $name, $key);
     return $result;
 }
コード例 #15
0
ファイル: Cache.php プロジェクト: indigo423/blog.no42.org
 /**
  * Returns a boolean state of whether or not the item exists in the cache based on id key
  *
  * @param string $id    the id of the cached data entry
  * @return bool         true if the cached items exists
  */
 public function contains($id)
 {
     if ($this->enabled) {
         return $this->driver->contains($id);
     }
     return false;
 }
コード例 #16
0
 /**
  * Add uri based on route.
  *
  * @param array $options
  */
 protected function processRoute(array &$options = array())
 {
     if (!empty($options['route'])) {
         $params = array();
         if (isset($options['routeParameters'])) {
             $params = $options['routeParameters'];
         }
         $cacheKey = null;
         $hasInCache = false;
         $uri = null;
         if ($this->cache) {
             $cacheKey = $this->getCacheKey('route_uri', $options['route'] . ($params ? serialize($params) : ''));
             if ($this->cache->contains($cacheKey)) {
                 $uri = $this->cache->fetch($cacheKey);
                 $hasInCache = true;
             }
         }
         if (!$hasInCache) {
             $absolute = false;
             if (isset($options['routeAbsolute'])) {
                 $absolute = $options['routeAbsolute'];
             }
             $uri = $this->router->generate($options['route'], $params, $absolute);
             if ($this->cache) {
                 $this->cache->save($cacheKey, $uri);
             }
         }
         $options['uri'] = $uri;
         $options = array_merge_recursive(array('extras' => array('routes' => array($options['route']), 'routesParameters' => array($options['route'] => $params))), $options);
     }
 }
コード例 #17
0
ファイル: HttpLoader.php プロジェクト: alebon/graviton
 /**
  * @inheritDoc
  *
  * @param string $input url
  *
  * @return ApiDefinition
  */
 public function load($input)
 {
     $retVal = null;
     if (isset($this->strategy)) {
         $request = $this->client->get($input);
         $this->applyCurlOptions($request);
         if (isset($this->cache) && $this->cache->contains($this->options['storeKey'])) {
             $content = $this->cache->fetch($this->options['storeKey']);
             if (empty($content)) {
                 $content = $this->fetchFile($request);
             }
         } else {
             $content = $this->fetchFile($request);
         }
         // store current host (name or ip) serving the API. This MUST be the host only and does not include the
         // scheme nor sub-paths. It MAY include a port. If the host is not included, the host serving the
         // documentation is to be used (including the port)
         $fallbackHost = array();
         $fallbackHost['host'] = sprintf('%s://%s:%d', $request->getScheme(), $request->getHost(), $request->getPort());
         if ($this->strategy->supports($content)) {
             $retVal = $this->strategy->process($content, $fallbackHost);
         }
     }
     return $retVal;
 }
コード例 #18
0
 /**
  * Return the user's environments.
  *
  * @param Project $project       The project.
  * @param bool    $refresh       Whether to refresh the list.
  * @param bool    $updateAliases Whether to update Drush aliases if the list changes.
  *
  * @return Environment[] The user's environments.
  */
 public function getEnvironments(Project $project = null, $refresh = false, $updateAliases = true)
 {
     $project = $project ?: $this->getSelectedProject();
     $projectId = $project->getProperty('id');
     $cacheKey = 'environments:' . $projectId;
     $cached = self::$cache->contains($cacheKey);
     if ($refresh || !$cached) {
         $environments = array();
         $toCache = array();
         foreach ($project->getEnvironments() as $environment) {
             $environments[$environment['id']] = $environment;
             $toCache[$environment['id']] = $environment->getData();
         }
         // Recreate the aliases if the list of environments has changed.
         if ($updateAliases && (!$cached || array_diff_key($environments, self::$cache->fetch($cacheKey)))) {
             $this->updateDrushAliases($project, $environments);
         }
         self::$cache->save($cacheKey, $toCache, $this->environmentsTtl);
     } else {
         $environments = array();
         $connector = $this->getClient(false)->getConnector();
         $endpoint = $project->hasLink('self') ? $project->getLink('self', true) : $project['endpoint'];
         $client = $connector->getClient();
         foreach ((array) self::$cache->fetch($cacheKey) as $id => $data) {
             $environments[$id] = Environment::wrap($data, $endpoint, $client);
         }
     }
     return $environments;
 }
コード例 #19
0
ファイル: AclCache.php プロジェクト: Dren-x/mobit
 /**
  * Retrieves an ACL for the given key from the cache
  *
  * @param string $key
  *
  * @return null|\Symfony\Component\Security\Acl\Model\AclInterface
  */
 private function getFromCacheByKey($key)
 {
     if (!$this->cache->contains($key)) {
         return null;
     }
     $serialized = $this->cache->fetch($key);
     return $this->unserializeAcl($serialized);
 }
コード例 #20
0
 /**
  * Gets item from Cache.
  *
  * @param string $key under which the item is stored
  *
  * @return \iveeCore\ICacheable
  * @throws \iveeCore\Exceptions\KeyNotFoundInCacheException if key is not found
  */
 public function getItem($key)
 {
     if (!$this->cache->contains($key)) {
         $exceptionClass = Config::getIveeClassName('KeyNotFoundInCacheException');
         throw new $exceptionClass("Key not found in cache.");
     }
     $item = $this->cache->fetch($key);
     $this->hits++;
     return $item;
 }
コード例 #21
0
 /**
  * {@inheritdoc}
  */
 public function getTheme()
 {
     /* @var ThemeAwareTenantInterface $tenant */
     $tenant = $this->tenantContext->getTenant();
     $key = md5($tenant->getCode());
     if (array_key_exists($key, $this->themes)) {
         return $this->themes[$key];
     }
     if ($this->cacheService->contains('theme_' . $key)) {
         return $this->themes[$key] = $this->cacheService->fetch('theme_' . $key);
     }
     $theme = $this->themeRepository->findOneByName($this->resolveThemeName($tenant));
     unset($tenant);
     if (null === $theme) {
         throw new NoThemeException();
     }
     $this->themes[$key] = $theme;
     $this->cacheService->save('theme_' . $key, $theme, 600);
     return $theme;
 }
コード例 #22
0
 /**
  * @return array
  */
 public function getAll()
 {
     $key = 'categories_slug';
     if ($this->cache->contains($key)) {
         return $this->cache->fetch($key);
     }
     /** @var Category[] $categories */
     $categories = $this->categoryRepository->findWithPublishedArticles();
     $categoriesSlugs = [];
     foreach ($categories as $category) {
         $slug = "/{$category->getSlug()}/";
         $parent = $category;
         /** @var Category|null $parent */
         while ($parent = $parent->getParent()) {
             $slug = "/{$parent->getSlug()}{$slug}";
         }
         $categoriesSlugs[$category->getId()] = $slug;
     }
     $this->cache->save($key, $categoriesSlugs);
     return $categoriesSlugs;
 }
コード例 #23
0
 public function refreshFeed() : array
 {
     $cacheId = $this->blogOptions->getCacheKey();
     $feed = Reader::import($this->blogOptions->getFeed());
     $feed = $this->processFeed($feed);
     // If no feed has been cached yet, cache current one and return
     if (!$this->feedCache->contains($cacheId)) {
         $this->templatesCache->deleteAll();
         $this->feedCache->save($cacheId, $feed);
         return $feed;
     }
     // Check if the last feed has changed, otherwise, return
     $cachedFeed = $this->feedCache->fetch($cacheId);
     if ($cachedFeed[0]['link'] === $feed[0]['link']) {
         return $feed;
     }
     // If the feed has changed, clear all cached elements so that views are refreshed, and cache feed too
     $this->templatesCache->deleteAll();
     $this->feedCache->save($cacheId, $feed);
     return $feed;
 }
コード例 #24
0
ファイル: HelpLinkProvider.php プロジェクト: Maksold/platform
 /**
  * Get help link URL.
  *
  * @return string
  */
 public function getHelpLinkUrl()
 {
     if ($this->cache && $this->cache->contains($this->requestRoute)) {
         $helpLink = $this->cache->fetch($this->requestRoute);
     } else {
         $helpLink = $this->constructedHelpLinkUrl();
         if ($this->cache) {
             $this->cache->save($this->requestRoute, $helpLink);
         }
     }
     return $helpLink;
 }
コード例 #25
0
 /**
  * @param $controllerReference
  * @param array $options
  * @return string
  */
 public function renderCached(ControllerReference $controllerReference, $options = [])
 {
     $key = $controllerReference->controller;
     if ($controllerReference->attributes !== []) {
         $key .= json_encode($controllerReference->attributes);
     }
     if ($controllerReference->query !== []) {
         $key .= json_encode($controllerReference->query);
     }
     if ($this->cache->contains($key)) {
         return $this->cache->fetch($key);
     }
     $renderedContent = $this->renderFragment($controllerReference, $options);
     $this->cache->save($key, $renderedContent, $this->sidebarCacheLifeTime);
     return $renderedContent;
 }
コード例 #26
0
ファイル: I18nCacheUtils.php プロジェクト: alebon/graviton
 /**
  * this shall be called by a Translator.
  * it adds our additions to the already existent ones in the Translator and returns it.
  * as this is called quite often, we cache the final result (the full map including the translator resources)
  * and only regenerate that when a *new* domain has been added. basic invalidations by the PostPersistListener
  * will *not* result in a rebuild here - only if a new domain has been added.
  *
  * @param array $resources the resources array of the translator
  *
  * @return array the finalized map containing translator resources and our additions
  */
 public function getResources($resources)
 {
     $finalResources = null;
     // do we have a full resource map in the cache already? (full = translator + additions)
     if ($this->cache->contains($this->cacheKeyFinalResource)) {
         $finalResources = $this->cache->fetch($this->cacheKeyFinalResource);
     }
     // do we have cached additions?
     if (!is_array($finalResources) && $this->cache->contains($this->cacheKey)) {
         // merge the two together, always keep an eye to not duplicate (paths are different!)
         $finalResources = $this->mergeResourcesWithAdditions($resources);
         // cache it
         $this->cache->save($this->cacheKeyFinalResource, $finalResources);
     }
     // so, did we got anything?
     if (is_array($finalResources)) {
         $resources = $finalResources;
     }
     return $resources;
 }
コード例 #27
0
 /**
  * @param               $yaml
  * @param CacheProvider $cache
  */
 public function __construct($yaml, CacheProvider $cache = null)
 {
     if ($cache instanceof CacheProvider) {
         if (strpos($yaml, "\n") === false && is_file($yaml)) {
             $yaml = file_get_contents($yaml);
         }
         $key = md5($yaml);
         if ($cache->contains($key)) {
             $result = $cache->fetch($key);
         } else {
             $result = Yaml::parse($yaml);
             $cache->save($key, $result);
         }
     } else {
         $result = Yaml::parse($yaml);
     }
     if (!isset($result)) {
         $result = array();
     }
     parent::__construct($result);
 }
コード例 #28
0
ファイル: QueryHelper.php プロジェクト: thewunder/corma
 /**
  * Returns table metadata for the provided table
  *
  * @param string $table
  * @return array column => accepts null (bool)
  */
 public function getDbColumns($table)
 {
     $key = 'db_columns.' . $table;
     if ($this->cache->contains($key)) {
         return $this->cache->fetch($key);
     } else {
         $qb = $this->db->createQueryBuilder();
         $database = $this->db->getDatabase();
         $qb->select('COLUMN_NAME AS ' . $this->db->quoteIdentifier('COLUMN_NAME'), 'IS_NULLABLE AS ' . $this->db->quoteIdentifier('IS_NULLABLE'))->from('information_schema.COLUMNS')->where('TABLE_SCHEMA = ?')->setParameter(0, $database)->andWhere('TABLE_NAME = ?')->setParameter(1, $table);
         $dbColumnInfo = $qb->execute()->fetchAll(\PDO::FETCH_OBJ);
         if (empty($dbColumnInfo)) {
             throw new InvalidArgumentException("The table {$database}.{$table} does not exist");
         }
         $dbColumns = [];
         foreach ($dbColumnInfo as $column) {
             $dbColumns[$column->COLUMN_NAME] = $column->IS_NULLABLE == 'YES' ? true : false;
         }
         $this->cache->save($key, $dbColumns);
         return $dbColumns;
     }
 }
コード例 #29
0
 /**
  * Get route information based on MenuItem options
  *
  * @param  array         $options
  * @return array|boolean
  */
 protected function getRouteInfo(array $options = array())
 {
     $key = null;
     $cacheKey = null;
     $hasInCache = false;
     if (array_key_exists('route', $options)) {
         if ($this->cache) {
             $cacheKey = $this->getCacheKey('route_acl', $options['route']);
             if ($this->cache->contains($cacheKey)) {
                 $key = $this->cache->fetch($cacheKey);
                 $hasInCache = true;
             }
         }
         if (!$hasInCache) {
             $key = $this->getRouteInfoByRouteName($options['route']);
         }
     } elseif (array_key_exists('uri', $options)) {
         if ($this->cache) {
             $cacheKey = $this->getCacheKey('uri_acl', $options['uri']);
             if ($this->cache->contains($cacheKey)) {
                 $key = $this->cache->fetch($cacheKey);
                 $hasInCache = true;
             }
         }
         if (!$hasInCache) {
             $key = $this->getRouteInfoByUri($options['uri']);
         }
     }
     if ($this->cache && $cacheKey && !$hasInCache) {
         $this->cache->save($cacheKey, $key);
     }
     $info = explode(self::CONTROLLER_ACTION_DELIMITER, $key);
     if (count($info) == 2) {
         return array('controller' => $info[0], 'action' => $info[1], 'key' => $key);
     } else {
         return false;
     }
 }
コード例 #30
0
ファイル: Cache.php プロジェクト: jacobjjc/PageKit-framework
 /**
  * {@inheritdoc}
  */
 public function contains($id)
 {
     return $this->provider->contains($id);
 }