Exemple #1
0
 /**
  * Generate url based on $name and $parameters
  *
  * @param string $name Name of the route to use.
  * @param array $parameters Parameters for the route
  * @param bool $absolute
  * @return string
  */
 public function generate($name, $parameters = array(), $absolute = false)
 {
     asort($parameters);
     $key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . json_encode($parameters) . intval($absolute);
     if ($this->cache->hasKey($key)) {
         return $this->cache->get($key);
     } else {
         $url = parent::generate($name, $parameters, $absolute);
         $this->cache->set($key, $url, 3600);
         return $url;
     }
 }
Exemple #2
0
 /**
  * @param string $key
  * @return bool
  */
 public function isCached($key)
 {
     if (is_null($this->cache)) {
         return false;
     }
     $key = $this->getCacheKey($key);
     return $this->cache->hasKey($key);
 }
 /**
  * @param ISubscription $subscription
  * @return string
  */
 protected function getData(ISubscription $subscription)
 {
     $id = $subscription->getId();
     $url = $subscription->getUrl();
     $cacheId = implode('::', [$id, $url]);
     if ($this->cache->hasKey($cacheId)) {
         return $this->cache->get($cacheId);
     } else {
         $curl = curl_init();
         $data = null;
         $this->prepareRequest($curl, $url);
         $this->getRequestData($curl, $data);
         $this->validateRequest($curl);
         $this->cache->set($cacheId, $data, 60 * 60 * 2);
         return $data;
     }
 }
Exemple #4
0
 /**
  * Fetches an object from the API.
  * If the object is cached already or a
  * failed "doesn't exist" response was cached,
  * that one will be returned.
  *
  * @param string $path
  * @return \OpenCloud\OpenStack\ObjectStorage\Resource\DataObject|bool object
  * or false if the object did not exist
  */
 private function fetchObject($path)
 {
     if ($this->objectCache->hasKey($path)) {
         // might be "false" if object did not exist from last check
         return $this->objectCache->get($path);
     }
     try {
         $object = $this->getContainer()->getPartialObject($path);
         $this->objectCache->set($path, $object);
         return $object;
     } catch (ClientErrorResponseException $e) {
         // this exception happens when the object does not exist, which
         // is expected in most cases
         $this->objectCache->set($path, false);
         return false;
     } catch (ClientErrorResponseException $e) {
         // Expected response is "404 Not Found", so only log if it isn't
         if ($e->getResponse()->getStatusCode() !== 404) {
             \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
         }
         return false;
     }
 }