/**
  * Cache validated response
  *
  * @param ValidateRequest $validateRequest
  * @param $storeId
  * @return ValidateResult
  * @throws \SoapFault
  */
 public function validate(ValidateRequest $validateRequest, $storeId)
 {
     $addressCacheKey = $this->getCacheKey($validateRequest->getAddress()) . $storeId;
     $validateResult = @unserialize($this->cache->load($addressCacheKey));
     if ($validateResult instanceof ValidateResult) {
         $this->avaTaxLogger->addDebug('Loaded \\AvaTax\\ValidateResult from cache.', ['request' => var_export($validateRequest, true), 'result' => var_export($validateResult, true), 'cache_key' => $addressCacheKey]);
         return $validateResult;
     }
     try {
         $addressService = $this->interactionAddress->getAddressService($this->type, $storeId);
         $validateResult = $addressService->validate($validateRequest);
         $serializedValidateResult = serialize($validateResult);
         $this->cache->save($serializedValidateResult, $addressCacheKey, [Config::AVATAX_CACHE_TAG]);
         $validAddress = isset($validateResult->getValidAddresses()[0]) ? $validateResult->getValidAddresses()[0] : null;
         $validAddressCacheKey = $this->getCacheKey($validAddress);
         $this->avaTaxLogger->addDebug('Loaded \\AvaTax\\ValidateResult from SOAP.', ['request' => var_export($validateRequest, true), 'result' => var_export($validateResult, true)]);
         $this->cache->save($serializedValidateResult, $validAddressCacheKey, [Config::AVATAX_CACHE_TAG]);
     } catch (LocalizedException $e) {
         $this->avaTaxLogger->addDebug('\\AvaTax\\ValidateResult no valid address found from SOAP.', ['result' => var_export($validateResult, true)]);
     } catch (\SoapFault $e) {
         $this->avaTaxLogger->error("Exception: \n" . $e->getMessage() . "\n" . $e->faultstring, ['request' => var_export($addressService->__getLastRequest(), true), 'result' => var_export($addressService->__getLastResponse(), true)]);
         throw $e;
     }
     return $validateResult;
 }
예제 #2
0
 /**
  * Checks whether some request to rates have already been done, so we have cache for it
  * Used to reduce number of same requests done to carrier service during one session
  *
  * Returns cached response or null
  *
  * @param string|array $requestParams
  * @return null|string
  */
 public function getCachedQuotes($requestParams, $carrierCode)
 {
     $key = $this->getQuotesCacheKey($requestParams, $carrierCode);
     // return isset(self::$quotesCache[$key]) ? self::$quotesCache[$key] : null;
     $cachedResult = $this->cache->load($key);
     return $cachedResult ? unserialize($cachedResult) : $cachedResult;
 }
예제 #3
0
파일: Remote.php 프로젝트: swissup/core
 /**
  * Retrieve component names and configs from remote satis repository
  *
  * @return \Traversable
  */
 public function getComponentsInfo()
 {
     try {
         if (!($responseBody = $this->cache->load(self::RESPONSE_CACHE_KEY))) {
             $responseBody = $this->fetch($this->getFeedUrl());
             $this->cache->save($responseBody, self::RESPONSE_CACHE_KEY, [], 86400);
         }
         $response = $this->jsonHelper->jsonDecode($responseBody);
     } catch (\Exception $e) {
         $response = [];
         // Swissup_Subscription will be added below - used by
         // subscription activation module
     }
     if (!is_array($response)) {
         $response = [];
     }
     if (!empty($response['packages'])) {
         $modules = [];
         foreach ($response['packages'] as $packageName => $info) {
             $versions = array_keys($info);
             $latestVersion = array_reduce($versions, function ($carry, $item) {
                 if (version_compare($carry, $item) === -1) {
                     $carry = $item;
                 }
                 return $carry;
             });
             if (!empty($info[$latestVersion]['type']) && $info[$latestVersion]['type'] === 'metapackage') {
                 continue;
             }
             (yield [$packageName, $info[$latestVersion]]);
         }
     }
     (yield ['swissup/subscription', ['name' => 'swissup/subscription', 'type' => 'subscription-plan', 'description' => 'SwissUpLabs Modules Subscription', 'version' => '', 'extra' => ['swissup' => ['links' => ['store' => 'https://swissuplabs.com', 'download' => 'https://swissuplabs.com/subscription/customer/products/', 'identity_key' => 'https://swissuplabs.com/license/customer/identity/']]]]]);
 }
예제 #4
0
 /**
  * {@inheritDoc}
  */
 public function get($cartId)
 {
     $this->quoteRepository->get($cartId);
     $msgCacheId = $cartId . self::CACHE_ID_POSTFIX;
     $giftMsg = $this->cache->load($msgCacheId);
     if (!$giftMsg) {
         throw new NoSuchEntityException(__('There is no gift message in the cart with provided id'));
     }
     return unserialize($giftMsg);
 }
예제 #5
0
 /**
  * {@inheritDoc}
  */
 public function get($cartId, $itemId)
 {
     $this->getQuoteItem($cartId, $itemId);
     $msgCacheId = $itemId . self::CACHE_ID_POSTFIX;
     $giftMsg = $this->cache->load($msgCacheId);
     if (!$giftMsg) {
         throw new NoSuchEntityException(__('There is no gift message for item with provided id in the cart'));
     }
     return unserialize($giftMsg);
 }
예제 #6
0
 /**
  * Get invalidate types codes
  *
  * @return array
  */
 protected function _getInvalidatedTypes()
 {
     $types = $this->_cache->load(self::INVALIDATED_TYPES);
     if ($types) {
         $types = unserialize($types);
     } else {
         $types = [];
     }
     return $types;
 }
예제 #7
0
 /**
  * Load data from the cache
  *
  * @param string $cacheKey Cache key.
  *
  * @return mixed
  */
 public function loadCache($cacheKey)
 {
     if (!isset($this->localCache[$cacheKey])) {
         $data = $this->cache->load($cacheKey);
         if ($data) {
             $data = unserialize($data);
         }
         $this->localCache[$cacheKey] = $data;
     }
     return $this->localCache[$cacheKey];
 }
예제 #8
0
 /**
  * @param \Magento\Catalog\Model\ResourceModel\Config $config
  * @param callable $proceed
  * @return array
  */
 public function aroundGetAttributesUsedForSortBy(\Magento\Catalog\Model\ResourceModel\Config $config, \Closure $proceed)
 {
     $cacheId = self::PRODUCT_LISTING_SORT_BY_ATTRIBUTES_CACHE_ID . $config->getEntityTypeId() . '_' . $config->getStoreId();
     if ($this->isCacheEnabled && ($attributes = $this->cache->load($cacheId))) {
         return unserialize($attributes);
     }
     $attributes = $proceed();
     if ($this->isCacheEnabled) {
         $this->cache->save(serialize($attributes), $cacheId, [\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]);
     }
     return $attributes;
 }
예제 #9
0
 /**
  * @param \Magento\Eav\Model\Resource\Entity\Attribute $subject
  * @param callable $proceed
  * @param int $attributeId
  * @return array
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundGetStoreLabelsByAttributeId(\Magento\Eav\Model\Resource\Entity\Attribute $subject, \Closure $proceed, $attributeId)
 {
     $cacheId = self::STORE_LABEL_ATTRIBUTE . $attributeId;
     if ($this->isCacheEnabled && ($storeLabels = $this->cache->load($cacheId))) {
         return unserialize($storeLabels);
     }
     $storeLabels = $proceed($attributeId);
     if ($this->isCacheEnabled) {
         $this->cache->save(serialize($storeLabels), $cacheId, [\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]);
     }
     return $storeLabels;
 }
예제 #10
0
 /**
  * Check verification result and return true if system must to show notification message
  *
  * @return bool
  */
 private function _canShowNotification()
 {
     if ($this->_cache->load(self::VERIFICATION_RESULT_CACHE_KEY)) {
         return false;
     }
     if ($this->_isFileAccessible()) {
         return true;
     }
     $adminSessionLifetime = (int) $this->_backendConfig->getValue('admin/security/session_lifetime');
     $this->_cache->save(true, self::VERIFICATION_RESULT_CACHE_KEY, [], $adminSessionLifetime);
     return false;
 }
예제 #11
0
 /**
  * {@inheritdoc}
  */
 public function getThemeById($themeId)
 {
     $theme = $this->cache->load('theme-by-id-' . $themeId);
     if ($theme) {
         return unserialize($theme);
     }
     /** @var $themeModel \Magento\Framework\View\Design\ThemeInterface */
     $themeModel = $this->themeFactory->create();
     $themeModel->load($themeId);
     if ($themeModel->getId()) {
         $this->cache->save(serialize($themeModel), 'theme-by-id-' . $themeId);
     }
     return $themeModel;
 }
예제 #12
0
파일: Observer.php 프로젝트: aiesh/magento2
 /**
  * Clean existed jobs
  *
  * @param string $groupId
  * @return $this
  */
 protected function _cleanup($groupId)
 {
     // check if history cleanup is needed
     $lastCleanup = (int) $this->_cache->load(self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . $groupId);
     $historyCleanUp = (int) $this->_scopeConfig->getValue('system/cron/' . $groupId . '/' . self::XML_PATH_HISTORY_CLEANUP_EVERY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     if ($lastCleanup > time() - $historyCleanUp * self::SECONDS_IN_MINUTE) {
         return $this;
     }
     /**
      * @var \Magento\Cron\Model\Resource\Schedule\Collection $history
      */
     $history = $this->_scheduleFactory->create()->getCollection()->addFieldToFilter('status', array('in' => array(Schedule::STATUS_SUCCESS, Schedule::STATUS_MISSED, Schedule::STATUS_ERROR)))->load();
     $historySuccess = (int) $this->_scopeConfig->getValue('system/cron/' . $groupId . '/' . self::XML_PATH_HISTORY_SUCCESS, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $historyFailure = (int) $this->_scopeConfig->getValue('system/cron/' . $groupId . '/' . self::XML_PATH_HISTORY_FAILURE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $historyLifetimes = array(Schedule::STATUS_SUCCESS => $historySuccess * self::SECONDS_IN_MINUTE, Schedule::STATUS_MISSED => $historyFailure * self::SECONDS_IN_MINUTE, Schedule::STATUS_ERROR => $historyFailure * self::SECONDS_IN_MINUTE);
     $now = time();
     /** @var Schedule $record */
     foreach ($history as $record) {
         if (strtotime($record->getExecutedAt()) < $now - $historyLifetimes[$record->getStatus()]) {
             $record->delete();
         }
     }
     // save time history cleanup was ran with no expiration
     $this->_cache->save(time(), self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . $groupId, array('crontab'), null);
     return $this;
 }
 /**
  * Clean existed jobs
  *
  * @param string $groupId
  * @return $this
  */
 protected function _cleanup($groupId)
 {
     // check if history cleanup is needed
     $lastCleanup = (int) $this->_cache->load(self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . $groupId);
     $historyCleanUp = (int) $this->_scopeConfig->getValue('system/cron/' . $groupId . '/' . self::XML_PATH_HISTORY_CLEANUP_EVERY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     if ($lastCleanup > $this->timezone->scopeTimeStamp() - $historyCleanUp * self::SECONDS_IN_MINUTE) {
         return $this;
     }
     // check how long the record should stay unprocessed before marked as MISSED
     $scheduleLifetime = (int) $this->_scopeConfig->getValue('system/cron/' . $groupId . '/' . self::XML_PATH_SCHEDULE_LIFETIME, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $scheduleLifetime = $scheduleLifetime * self::SECONDS_IN_MINUTE;
     /**
      * @var \Magento\Cron\Model\ResourceModel\Schedule\Collection $history
      */
     $history = $this->_scheduleFactory->create()->getCollection()->addFieldToFilter('status', ['in' => [Schedule::STATUS_SUCCESS, Schedule::STATUS_MISSED, Schedule::STATUS_ERROR]])->load();
     $historySuccess = (int) $this->_scopeConfig->getValue('system/cron/' . $groupId . '/' . self::XML_PATH_HISTORY_SUCCESS, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $historyFailure = (int) $this->_scopeConfig->getValue('system/cron/' . $groupId . '/' . self::XML_PATH_HISTORY_FAILURE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $historyLifetimes = [Schedule::STATUS_SUCCESS => $historySuccess * self::SECONDS_IN_MINUTE, Schedule::STATUS_MISSED => $historyFailure * self::SECONDS_IN_MINUTE, Schedule::STATUS_ERROR => $historyFailure * self::SECONDS_IN_MINUTE];
     $now = $this->timezone->scopeTimeStamp();
     /** @var Schedule $record */
     foreach ($history as $record) {
         $checkTime = $record->getExecutedAt() ? strtotime($record->getExecutedAt()) : strtotime($record->getScheduledAt()) + $scheduleLifetime;
         if ($checkTime < $now - $historyLifetimes[$record->getStatus()]) {
             $record->delete();
         }
     }
     // save time history cleanup was ran with no expiration
     $this->_cache->save($this->timezone->scopeTimeStamp(), self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . $groupId, ['crontab'], null);
     return $this;
 }
예제 #14
0
 /**
  * Get codes of all entity type attributes
  *
  * @param  mixed $entityType
  * @param  \Magento\Framework\DataObject $object
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function getEntityAttributeCodes($entityType, $object = null)
 {
     $entityType = $this->getEntityType($entityType);
     $attributeSetId = 0;
     $storeId = 0;
     if ($object instanceof \Magento\Framework\DataObject) {
         $attributeSetId = $object->getAttributeSetId() ?: $attributeSetId;
         $storeId = $object->getStoreId() ?: $storeId;
     }
     $cacheKey = self::ATTRIBUTES_CODES_CACHE_ID . $entityType->getId() . '-' . $storeId . '-' . $attributeSetId;
     if (isset($this->_attributeCodes[$cacheKey])) {
         return $this->_attributeCodes[$cacheKey];
     }
     if ($this->isCacheEnabled() && ($attributes = $this->_cache->load($cacheKey))) {
         $this->_attributeCodes[$cacheKey] = unserialize($attributes);
         return $this->_attributeCodes[$cacheKey];
     }
     if ($attributeSetId) {
         $attributesInfo = $this->_universalFactory->create($entityType->getEntityAttributeCollection())->setEntityTypeFilter($entityType)->setAttributeSetFilter($attributeSetId)->addStoreLabel($storeId)->getData();
         $attributes = [];
         foreach ($attributesInfo as $attributeData) {
             $attributes[] = $attributeData['attribute_code'];
             $this->_createAttribute($entityType, $attributeData);
         }
     } else {
         $this->_initAttributes($entityType);
         $attributes = array_keys($this->_attributeData[$entityType->getEntityTypeCode()]);
     }
     $this->_attributeCodes[$cacheKey] = $attributes;
     if ($this->isCacheEnabled()) {
         $this->_cache->save(serialize($attributes), $cacheKey, [\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]);
     }
     return $attributes;
 }
예제 #15
0
 /**
  * Cache validated response
  *
  * @param GetTaxRequest $getTaxRequest
  * @param $storeId
  * @param bool $useCache
  * @return GetTaxResult
  * @throws LocalizedException
  */
 public function getTax(GetTaxRequest $getTaxRequest, $storeId, $useCache = false)
 {
     $cacheKey = $this->getCacheKey($getTaxRequest) . $storeId;
     $getTaxResult = @unserialize($this->cache->load($cacheKey));
     if ($getTaxResult instanceof GetTaxResult && $useCache) {
         $this->avaTaxLogger->addDebug('Loaded \\AvaTax\\GetTaxResult from cache.', ['result' => var_export($getTaxResult, true), 'cache_key' => $cacheKey]);
         return $getTaxResult;
     }
     $getTaxResult = $this->taxInteraction->getTaxService($this->type, $storeId)->getTax($getTaxRequest);
     $this->avaTaxLogger->addDebug('Loaded \\AvaTax\\GetTaxResult from SOAP.', ['request' => var_export($getTaxRequest, true), 'result' => var_export($getTaxResult, true)]);
     // Only cache successful requests
     if ($useCache && $getTaxResult->getResultCode() == \AvaTax\SeverityLevel::$Success) {
         $serializedGetTaxResult = serialize($getTaxResult);
         $this->cache->save($serializedGetTaxResult, $cacheKey, [Config::AVATAX_CACHE_TAG], self::CACHE_LIFETIME);
     }
     return $getTaxResult;
 }
예제 #16
0
 /**
  * @return array
  */
 public function getFeeds()
 {
     if ($this->dataProvider === null) {
         return [];
     }
     $cache = false;
     if ($this->dataProvider->getCacheKey() && $this->dataProvider->getCacheLifetime()) {
         $cache = $this->cache->load($this->dataProvider->getCacheKey());
     }
     if ($cache) {
         return unserialize($cache);
     }
     $data = $this->dataProvider->getRssData();
     if ($this->dataProvider->getCacheKey() && $this->dataProvider->getCacheLifetime()) {
         $this->cache->save(serialize($data), $this->dataProvider->getCacheKey(), ['rss'], $this->dataProvider->getCacheLifetime());
     }
     return $data;
 }
 /**
  * @param $openpayCustomerId
  * @return mixed|\Openpay\Client\Type\OpenpayCustomerType
  * @throws LocalizedException
  */
 public function get($openpayCustomerId)
 {
     $cacheIdentifier = $this->getCacheIdentifier($openpayCustomerId);
     $openpayCustomer = unserialize($this->cache->load($cacheIdentifier));
     if ($openpayCustomer === false) {
         try {
             $openpayCustomer = $this->customerAdapter->get($openpayCustomerId);
         } catch (OpenpayException $e) {
             $description = $e->getDescription();
             if (is_null($description)) {
                 $description = 'We could not retrieve your payment gateway information.';
             }
             throw new LocalizedException(__($description), $e);
         }
         $this->cache->save(serialize($openpayCustomer), $cacheIdentifier, [], self::CACHE_TIME_SECONDS);
     }
     return $openpayCustomer;
 }
예제 #18
0
 /**
  * Return attributes from cache
  *
  * @param string $entityType
  * @param string $suffix
  * @return object[]
  */
 public function getAttributes($entityType, $suffix = '')
 {
     if (in_array($entityType, $this->unsupportedTypes)) {
         return false;
     }
     if (isset($this->attributeInstances[$entityType . $suffix])) {
         return $this->attributeInstances[$entityType . $suffix];
     }
     if ($this->isAttributeCacheEnabled()) {
         $cacheKey = self::ATTRIBUTES_CACHE_PREFIX . $entityType . $suffix;
         $attributesData = $this->cache->load($cacheKey);
         if ($attributesData) {
             $attributes = unserialize($attributesData);
             $this->attributeInstances[$entityType . $suffix] = $attributes;
             return $attributes;
         }
     }
     return false;
 }
 /**
  * Returns cache status for given block.
  * @see AbstractBlock, method in class is protected in original version
  *
  * @param $block
  * @return bool
  */
 protected function getCacheStatus($block)
 {
     if ($this->getCacheLifetime($block) === null || !$this->_cacheState->isEnabled($block::CACHE_GROUP)) {
         return false;
     }
     $cacheKey = $block->getCacheKey();
     if (empty($cacheKey)) {
         return false;
     }
     $cacheData = $this->_cache->load($cacheKey);
     return isset($cacheData);
 }
예제 #20
0
 /**
  * Load data from the cache if exits. Use a callback on the current category virtual root if not yet present into the cache.
  *
  * @param string $callback name of the virtual rule method to be used for actual loading.
  *
  * @return mixed
  */
 private function loadUsingCache($callback)
 {
     $category = $this->getDataProvider()->getCategory();
     $cacheKey = implode('|', [$callback, $category->getStoreId(), $category->getId()]);
     $data = $this->cache->load($cacheKey);
     if ($data !== false) {
         $data = unserialize($data);
     }
     if ($data === false) {
         $virtualRule = $category->getVirtualRule();
         $data = call_user_func_array([$virtualRule, $callback], [$category]);
         $cacheData = serialize($data);
         $this->cache->save($cacheData, $cacheKey, [\Magento\Catalog\Model\Category::CACHE_TAG]);
     }
     return $data;
 }
예제 #21
0
파일: Config.php 프로젝트: aiesh/magento2
 /**
  * Initialize all entity types data
  *
  * @return $this
  */
 protected function _initEntityTypes()
 {
     if (is_array($this->_entityData)) {
         return $this;
     }
     \Magento\Framework\Profiler::start('EAV: ' . __METHOD__, array('group' => 'EAV', 'method' => __METHOD__));
     /**
      * try load information about entity types from cache
      */
     if ($this->_isCacheEnabled() && ($cache = $this->_cache->load(self::ENTITIES_CACHE_ID))) {
         $this->_entityData = unserialize($cache);
         foreach ($this->_entityData as $typeCode => $data) {
             $typeId = $data['entity_type_id'];
             $this->_addEntityTypeReference($typeId, $typeCode);
         }
         \Magento\Framework\Profiler::stop('EAV: ' . __METHOD__);
         return $this;
     }
     $entityTypesData = $this->_entityTypeFactory->create()->getCollection()->getData();
     $types = array();
     /**
      * prepare entity type data
      */
     foreach ($entityTypesData as $typeData) {
         if (!isset($typeData['attribute_model'])) {
             $typeData['attribute_model'] = 'Magento\\Eav\\Model\\Entity\\Attribute';
         }
         $typeCode = $typeData['entity_type_code'];
         $typeId = $typeData['entity_type_id'];
         $this->_addEntityTypeReference($typeId, $typeCode);
         $types[$typeCode] = $typeData;
     }
     $this->_entityData = $types;
     if ($this->_isCacheEnabled()) {
         $this->_cache->save(serialize($this->_entityData), self::ENTITIES_CACHE_ID, array(\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG));
     }
     \Magento\Framework\Profiler::stop('EAV: ' . __METHOD__);
     return $this;
 }