fetch() public method

public fetch ( $id )
 /**
  * @param string $key
  * @return mixed|null
  */
 public function get($key)
 {
     if (!$this->cache->contains($key)) {
         $this->loadSettings();
     }
     return $this->cache->fetch($key);
 }
Beispiel #2
0
 /**
  * @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;
 }
 /**
  * Gets the timestamp of the last update of database translations for the given locale
  *
  * @param string $locale
  * @return int|bool timestamp or false if the timestamp is not cached yet
  */
 public function getTimestamp($locale)
 {
     if (!isset($this->localCache[$locale])) {
         $this->localCache[$locale] = $this->cacheImpl->fetch($locale);
     }
     return $this->localCache[$locale];
 }
 /**
  * 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];
 }
 /**
  * @return \Heyday\Redirects\Redirect[]
  */
 public function get()
 {
     $key = $this->dataSource->getKey();
     if (!($result = $this->cache->fetch($key))) {
         $this->cache->save($key, $result = $this->dataSource->get());
     }
     return $result;
 }
 /**
  * @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];
 }
 /**
  * (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);
 }
 /**
  * @param DocumentFinder $finder For finding documents.
  * @param DocumentParser $parser For reading document annotations.
  * @param CacheProvider  $cache  Cache provider to store the meta data for later use.
  */
 public function __construct($finder, $parser, $cache = null)
 {
     $this->finder = $finder;
     $this->parser = $parser;
     $this->cache = $cache;
     if ($this->cache) {
         $this->mappings = $this->cache->fetch('ongr.metadata.mappings');
     }
 }
 /**
  * Get an item.
  *
  * @param  string $cacheId
  * @param  bool   $success
  *
  * @return mixed Data on success, null on failure
  */
 public function getItem($cacheId, &$success = null)
 {
     if (!$this->hasItem($cacheId)) {
         $success = false;
         return null;
     }
     $cacheId = $this->normalizeKey($cacheId);
     $success = true;
     return unserialize($this->cache->fetch($cacheId));
 }
Beispiel #10
0
 /**
  * {@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;
 }
 /**
  * {@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;
 }
Beispiel #12
0
 /**
  * Returns the data for the given key.
  *
  * @param  string $key     The key to search for.
  * @param  mixed  $default Default value to return if there is no data.
  *
  * @return mixed  The cached data, default value or null, if no cache entry exists for the given id.
  */
 public function get($key, $default = false)
 {
     $data = $this->cacheProvider->fetch($key);
     if ($data === false && $default !== false) {
         return $default;
     } elseif ($data === false) {
         return null;
     }
     return $data;
 }
 /**
  * @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);
     }
 }
Beispiel #14
0
 /**
  * @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);
             }
         }
     }
 }
Beispiel #15
0
 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;
 }
 /**
  * @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);
 }
Beispiel #17
0
 /**
  * Gets a flag indicates whether an entity or entity field is configurable or not.
  *
  * @param string      $className
  * @param string|null $fieldName
  * @return bool|null true if an entity or entity field is configurable;
  *                   false if not;
  *                   null if unknown (it means that "is configurable" flag was not set yet)
  */
 public function getConfigurable($className, $fieldName = null)
 {
     $flag = $this->modelCache->fetch($this->buildModelCacheKey($className, $fieldName));
     if ($flag === false) {
         // no cache entry exists
         $flag = null;
     } elseif ($flag === null) {
         // no cache entry exists and it say that an entity or entity field is not configurable
         $flag = false;
     }
     return $flag;
 }
Beispiel #18
0
 /**
  * {@inheritdoc}
  */
 public function getItem($key)
 {
     if (isset($this->deferred[$key])) {
         return $this->deferred[$key];
     }
     if (false === $this->provider->contains($key)) {
         return new CacheItem($key);
     }
     $item = $this->provider->fetch($key);
     $item->setHit(true);
     return $item;
 }
Beispiel #19
0
 /**
  * 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();
 }
Beispiel #21
0
 /**
  * @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;
 }
Beispiel #22
0
 /**
  * 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;
 }
 /**
  * Makes sure that metadata are loaded and cached
  */
 protected function ensureMetadataLoaded()
 {
     if ($this->localCache === null) {
         $data = null;
         if ($this->cache) {
             $data = $this->cache->fetch(self::CACHE_KEY);
         }
         if ($data) {
             $this->localCache = $data;
         } else {
             $this->loadMetadata();
         }
     }
 }
Beispiel #24
0
 /**
  * @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;
 }
Beispiel #25
0
 /**
  * Makes sure that tree data are loaded and cached
  */
 protected function ensureTreeLoaded()
 {
     if ($this->tree === null) {
         $treeData = null;
         if ($this->cache) {
             $treeData = $this->cache->fetch(self::CACHE_KEY);
         }
         if ($treeData) {
             $this->tree = $treeData;
         } else {
             $this->loadTree();
         }
     }
 }
 /**
  * @param \DateTime $date
  * @param \Hyper\AdsBundle\Entity\Zone[] $zones
  * @return array
  */
 private function getNumberOfBannersOfAllZonesInGivenDay(\DateTime $date, $zones)
 {
     static $warmUpZones = array();
     $formattedDate = $date->format(self::DATE_FORMAT);
     $zonesNumberMap = array();
     foreach ($zones as $zone) {
         if (!isset($warmUpZones[$zone->getId()])) {
             $this->warmUp($zone);
             $warmUpZones[$zone->getId()] = true;
         }
         $cacheId = self::CACHE_PREFIX . $zone->getId() . '_' . $formattedDate;
         $zonesNumberMap[$zone->getId() . '_' . $zone->getName()] = intval($this->cache->fetch($cacheId));
     }
     return $zonesNumberMap;
 }
 /**
  * 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;
 }
 /**
  * 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);
     }
 }
 /**
  * @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;
 }
 /**
  * Wrapper function to run shell commands. Supports local and remote commands
  * depending on the gitEnvironment details.
  *
  * @param string $command      command to run
  * @param bool   $cacheCommand command to run
  * @param bool   $trim         do not trim response. Maybe need for some command responses
  *
  * @return string Result of command
  *
  * @throws \RuntimeException
  */
 public function runCommand($command, $cacheCommand = true, $trim = true)
 {
     $response = '';
     if ($this->stopwatch) {
         $this->stopwatch->start('git_request', 'version_control');
     }
     $fullCommand = sprintf('cd %s && %s', $this->gitPath, $command);
     $cacheId = md5($this->gitEnvironment->getId() . $fullCommand);
     if ($this->gitEnvironment->getSsh() === true) {
         //Run remote command over ssh
         if ($cacheCommand === true) {
             $response = $this->cache->fetch($cacheId);
             if ($response === false) {
                 $response = $this->runRemoteCommand($fullCommand);
                 $this->cache->save($cacheId, $response);
             }
         } else {
             $response = $this->runRemoteCommand($fullCommand);
         }
     } else {
         //Run local commands
         $start = microtime(true);
         $response = $this->runLocalCommand($command);
         $this->logCommand($fullCommand, 'local', array(), $start);
     }
     return $trim === true ? trim($response) : $response;
 }