当前位置: 首页>>代码示例>>PHP>>正文


PHP CacheInterface::load方法代码示例

本文整理汇总了PHP中Magento\Framework\App\CacheInterface::load方法的典型用法代码示例。如果您正苦于以下问题:PHP CacheInterface::load方法的具体用法?PHP CacheInterface::load怎么用?PHP CacheInterface::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\App\CacheInterface的用法示例。


在下文中一共展示了CacheInterface::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 /**
  * 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;
 }
开发者ID:classyllama,项目名称:ClassyLlama_AvaTax,代码行数:33,代码来源:AddressService.php

示例2: getCachedQuotes

 /**
  * 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;
 }
开发者ID:shipperhq,项目名称:module-shipper,代码行数:16,代码来源:CarrierCache.php

示例3: getComponentsInfo

 /**
  * 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/']]]]]);
 }
开发者ID:swissup,项目名称:core,代码行数:39,代码来源:Remote.php

示例4: get

 /**
  * {@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);
 }
开发者ID:luo3555,项目名称:magento2-samples,代码行数:13,代码来源:CartRepository.php

示例5: get

 /**
  * {@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);
 }
开发者ID:marcinNS,项目名称:magento2-samples,代码行数:13,代码来源:ItemRepository.php

示例6: _getInvalidatedTypes

 /**
  * 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;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:15,代码来源:TypeList.php

示例7: loadCache

 /**
  * 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];
 }
开发者ID:smile-sa,项目名称:elasticsuite,代码行数:18,代码来源:Cache.php

示例8: aroundGetAttributesUsedForSortBy

 /**
  * @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;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:17,代码来源:Config.php

示例9: aroundGetStoreLabelsByAttributeId

 /**
  * @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;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:19,代码来源:Attribute.php

示例10: _canShowNotification

 /**
  * 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;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:17,代码来源:Security.php

示例11: getThemeById

 /**
  * {@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;
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:17,代码来源:ThemeProvider.php

示例12: _cleanup

 /**
  * 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;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:32,代码来源:Observer.php

示例13: _cleanup

 /**
  * 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;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:36,代码来源:ProcessCronQueueObserver.php

示例14: getEntityAttributeCodes

 /**
  * 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;
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:43,代码来源:Config.php

示例15: getTax

 /**
  * 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;
 }
开发者ID:classyllama,项目名称:ClassyLlama_AvaTax,代码行数:26,代码来源:TaxService.php


注:本文中的Magento\Framework\App\CacheInterface::load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。