コード例 #1
0
ファイル: Cache.php プロジェクト: wwtg99/flight2wwu
 /**
  * @param string $name
  * @return bool
  */
 public function has($name)
 {
     if ($this->cache) {
         return $this->cache->has($name);
     }
     return false;
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function getProducts($rentGuaranteeOfferingType, $propertyLettingType)
 {
     $parameters = array('rentGuaranteeOfferingType' => (int) $rentGuaranteeOfferingType, 'propertyLettingType' => (int) $propertyLettingType);
     // Always merge context parameters as this cache is unique per agent branch
     $cacheKey = $this->buildCacheKey(array_merge($parameters, $this->context->getParameters()));
     if ($this->cache->has($cacheKey)) {
         return $this->cache->get($cacheKey);
     }
     /** @var \Guzzle\Common\Collection $products */
     $products = $this->context->getProductClient()->getProducts($parameters);
     $this->cache->set($cacheKey, $products, 500);
     // Longer TTL for products
     return $products;
 }
コード例 #3
0
ファイル: Lookup.php プロジェクト: AlexEvesDeveloper/hl-stuff
 /**
  * Return a category of lookup items as a choice
  * array for use in form types
  *
  * @param string $categoryName
  * @return array
  */
 public function getCategoryAsChoices($categoryName)
 {
     $cacheKey = $this->buildCompoundCacheKey(array($categoryName));
     if ($this->cache->has($cacheKey)) {
         return $this->cache->get($cacheKey);
     }
     $choices = array();
     $items = $this->lookup->getCategoryByName($categoryName)->getItems();
     /** @var \Barbondev\IRISSDK\IndividualApplication\Lookup\Model\LookupItem $item */
     foreach ($items as $item) {
         $choices[$item->getId()] = $item->getName();
     }
     $this->cache->set($cacheKey, $choices);
     return $choices;
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function getProductPrice($agentSchemeNumber, $productId, $propertyLetType, $rentGuaranteeOfferingType, $shareOfRent, $policyLengthInMonths)
 {
     $parameters = array('productId' => (int) $productId, 'agentSchemeNumber' => (int) $agentSchemeNumber, 'propertyLetType' => (int) $propertyLetType, 'rentGuaranteeOfferingType' => (int) $rentGuaranteeOfferingType, 'shareOfRent' => (double) $shareOfRent, 'policyLengthInMonths' => (int) ($policyLengthInMonths ?: 0), 'guarantorSequenceNumber' => (int) 0, 'isRenewal' => (int) false);
     // Always merge context parameters as this cache is unique per agent branch
     $cacheKey = $this->buildCacheKey(array_merge($parameters, $this->context->getParameters()));
     if ($this->cache->has($cacheKey)) {
         return $this->cache->get($cacheKey);
     }
     /** @var \Barbondev\IRISSDK\IndividualApplication\Product\Model\ProductPrice $productPrice */
     try {
         $productPrice = $this->context->getProductClient()->getProductPrice($parameters);
     } catch (NotFoundException $e) {
         throw new ProductPriceNotFoundException(sprintf('Product price not found using parameters: ', print_r($parameters, true)));
     }
     $this->cache->set($cacheKey, $productPrice, 120);
     // Short TTL for this cache
     return $productPrice;
 }
コード例 #5
0
 public function testHasWithTtlExpired()
 {
     $key = 'key1';
     $value = 'value1';
     $ttl = 1;
     $this->cache->set($key, $value, $ttl);
     sleep($ttl + 1);
     $this->assertFalse($this->cache->has($key));
 }
コード例 #6
0
 public function testHasWithTtlExpired()
 {
     $this->cache->set('key1', 'value1', 1);
     sleep(2);
     $this->assertFalse($this->cache->has('key1'));
 }
コード例 #7
0
 /**
  * @dataProvider dataProvider
  */
 public function testHas()
 {
     $this->cache->set('key', 'value');
     $this->assertFalse($this->cache->has('key'));
 }