save() public method

public save ( $id, $data, $lifeTime )
Exemplo n.º 1
0
 /**
  * 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);
     }
 }
Exemplo n.º 2
0
 /**
  * @return array
  */
 private function loadSettings()
 {
     /** @var Setting $setting */
     foreach ($this->repository->findAll() as $setting) {
         $this->cache->save($setting->getKey(), $setting->getValue());
     }
 }
 /**
  * Puts data into the cache.
  *
  * @param string $id       The cache id.
  * @param mixed  $data     The cache entry/data.
  * @param int    $lifeTime The cache lifetime.
  *                         If != 0, sets a specific lifetime for this cache entry (0 => infinite lifeTime).
  *
  * @return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise.
  */
 public function save($id, $data, $lifeTime = null)
 {
     if (null === $lifeTime) {
         $lifeTime = $this->defaultLifetime;
     }
     return $this->cacheProvider->save($id, $data, $lifeTime);
 }
Exemplo n.º 4
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;
 }
 /**
  * Stores item in Cache.
  *
  * @param \iveeCore\ICacheable $item to be stored
  *
  * @return boolean true on success.
  */
 public function setItem(ICacheable $item)
 {
     $ttl = $item->getCacheExpiry() - time();
     if ($ttl < 1) {
         return false;
     }
     return $this->cache->save($item->getKey(), $item, $ttl);
 }
 /**
  * @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());
 }
 /**
  * @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;
 }
 /**
  * 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;
 }
Exemplo n.º 10
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;
 }
Exemplo n.º 11
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);
 }
Exemplo n.º 12
0
 /**
  * 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;
 }
Exemplo n.º 13
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;
 }
Exemplo n.º 14
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;
 }
Exemplo n.º 15
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;
 }
Exemplo n.º 16
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;
 }
 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);
     }
 }
Exemplo n.º 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;
 }
Exemplo n.º 19
0
 /**
  * Check (and update) any records that need to be updated from "published" to "held".
  */
 public function holdExpiredRecords()
 {
     foreach ($this->contentTypeNames as $contentTypeName) {
         $this->timedHandleRecords($contentTypeName, 'hold');
     }
     $this->cache->save(self::CACHE_KEY_HOLD, true, $this->interval);
 }
 /**
  * Makes sure that metadata for the given security type is loaded
  *
  * @param string $securityType The security type.
  */
 protected function ensureMetadataLoaded($securityType)
 {
     if (!isset($this->localCache[$securityType])) {
         $data = null;
         if ($this->cache) {
             $data = $this->cache->fetch($securityType);
         }
         if (!$data) {
             $securityConfigs = $this->securityConfigProvider->getConfigs();
             foreach ($securityConfigs as $securityConfig) {
                 if ($securityConfig->get('type') === $securityType) {
                     $className = $securityConfig->getId()->getClassName();
                     $label = '';
                     if ($this->entityConfigProvider->hasConfig($className)) {
                         $label = $this->entityConfigProvider->getConfig($className)->get('label');
                     }
                     $permissions = $securityConfig->get('permissions');
                     if (!$permissions || $permissions == 'All') {
                         $permissions = array();
                     } else {
                         $permissions = explode(';', $permissions);
                     }
                     $data[$className] = new EntitySecurityMetadata($securityType, $className, $securityConfig->get('group_name'), $label, $permissions);
                 }
             }
             if ($this->cache) {
                 $this->cache->save($securityType, $data);
             }
         }
         $this->localCache[$securityType] = $data;
     }
 }
Exemplo n.º 21
0
 /**
  * Makes sure that metadata for the given class are loaded
  *
  * @param string $className
  * @throws InvalidConfigurationException
  */
 protected function ensureMetadataLoaded($className)
 {
     if (!isset($this->localCache[$className])) {
         $data = null;
         if ($this->cache) {
             $data = $this->cache->fetch($className);
         }
         if (!$data) {
             if ($this->configProvider->hasConfig($className)) {
                 $config = $this->configProvider->getConfig($className);
                 try {
                     $ownerType = $config->get('owner_type');
                     $ownerFieldName = $config->get('owner_field_name');
                     $ownerColumnName = $config->get('owner_column_name');
                     $organizationFieldName = $config->get('organization_field_name');
                     $organizationColumnName = $config->get('organization_column_name');
                     if (!$organizationFieldName && $ownerType == OwnershipType::OWNER_TYPE_ORGANIZATION) {
                         $organizationFieldName = $ownerFieldName;
                         $organizationColumnName = $ownerColumnName;
                     }
                     $data = new OwnershipMetadata($ownerType, $ownerFieldName, $ownerColumnName, $organizationFieldName, $organizationColumnName);
                 } catch (\InvalidArgumentException $ex) {
                     throw new InvalidConfigurationException(sprintf('Invalid entity ownership configuration for "%s".', $className), 0, $ex);
                 }
             }
             if (!$data) {
                 $data = true;
             }
             if ($this->cache) {
                 $this->cache->save($className, $data);
             }
         }
         $this->localCache[$className] = $data;
     }
 }
 /**
  * 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);
     }
 }
Exemplo n.º 23
0
 /**
  * @param string $name
  * @param mixed $value string, int, boolean, object, ...
  * @param int $owner
  * @param null|string $group
  * @return $this
  * @throws \Doctrine\ORM\OptimisticLockException
  * @throws \Doctrine\ORM\ORMInvalidArgumentException
  */
 public function set($name, $value, $owner = null, $group = null)
 {
     try {
         $item = $this->get($name, $owner, $group);
     } catch (PropertyNotExistsException $ex) {
         $item = null;
     }
     $nname = null !== $owner ? $name . '_' . $owner : $name;
     if (null !== $item || !(array_key_exists($name, $this->defaults) && $this->defaults[$name] === $item)) {
         $setting = $this->em->getRepository('SettingsBundle:Setting')->findOneBy(['name' => $nname, 'ownerId' => $owner, 'group' => $group]);
         if (null === $setting) {
             $setting = new Setting();
         }
     } else {
         $setting = new Setting();
     }
     $setting->setName($nname);
     $setting->setValue($value);
     $setting->setOwnerId($owner);
     $setting->setGroup($group);
     $this->em->persist($setting);
     $this->em->flush($setting);
     if ($this->cacheProvider) {
         $this->cacheProvider->save($nname, serialize($setting));
     }
     return $this;
 }
 /**
  * @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;
 }
Exemplo n.º 25
0
 /**
  * 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;
 }
 /**
  * Loads metadata for the given security type and save them in cache
  *
  * @param $securityType
  */
 protected function loadMetadata($securityType)
 {
     $data = array();
     $securityConfigs = $this->securityConfigProvider->getConfigs();
     foreach ($securityConfigs as $securityConfig) {
         $className = $securityConfig->getId()->getClassName();
         if ($securityConfig->get('type') === $securityType && $this->extendConfigProvider->getConfig($className)->in('state', [ExtendScope::STATE_ACTIVE, ExtendScope::STATE_UPDATE])) {
             $label = '';
             if ($this->entityConfigProvider->hasConfig($className)) {
                 $label = $this->entityConfigProvider->getConfig($className)->get('label');
             }
             $permissions = $securityConfig->get('permissions');
             if (!$permissions || $permissions == 'All') {
                 $permissions = array();
             } else {
                 $permissions = explode(';', $permissions);
             }
             $data[$className] = new EntitySecurityMetadata($securityType, $className, $securityConfig->get('group_name'), $label, $permissions);
         }
     }
     if ($this->cache) {
         $this->cache->save($securityType, $data);
     }
     $this->localCache[$securityType] = $data;
 }
Exemplo n.º 27
0
 /**
  * Check (and update) any records that need to be updated from "published" to "held".
  */
 public function holdExpiredRecords()
 {
     foreach ($this->contentTypeNames as $contentTypeName) {
         $this->timedHandleRecords($contentTypeName, 'hold');
     }
     $this->cache->save(self::CACHE_KEY_HOLD, true, $this->config->get('general/caching/duration', 10));
 }
 /**
  * Puts data into the cache.
  *
  * @param string $id       The cache id.
  * @param mixed  $data     The cache entry/data.
  * @param int    $lifeTime The cache lifetime.
  *                         If != 0, sets a specific lifetime for this cache entry (0 => infinite lifeTime).
  *
  * @return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise.
  */
 public function save($id, $data, $lifeTime = null)
 {
     if (null === $lifeTime) {
         $lifeTime = $this->getDefaultLifetime();
     }
     return parent::save($id, $data, $lifeTime);
 }
 /**
  * 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];
 }
 /**
  * Adds metadata information to the cache storage.
  *
  * @param string $bundle
  * @param array  $mapping
  */
 private function cacheBundle($bundle, array $mapping)
 {
     if ($this->enableCache) {
         $this->mappings[$bundle] = $mapping;
         $this->cache->save('ongr.metadata.mappings', $this->mappings);
     }
 }