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


PHP CacheInterface::save方法代码示例

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


在下文中一共展示了CacheInterface::save方法的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: 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

示例3: saveCache

 /**
  * Save some data into an index cache.
  *
  * @param string   $cacheKey  Cache key.
  * @param mixed    $data      Data.
  * @param string[] $cacheTags Cache tags.
  * @param integer  $lifetime  Cache lifetime.
  */
 public function saveCache($cacheKey, $data, $cacheTags, $lifetime = self::DEFAULT_LIFETIME)
 {
     $this->localCache[$cacheKey] = $data;
     if (!is_string($data)) {
         $data = serialize($data);
     }
     $this->cache->save($data, $cacheKey, $cacheTags, $lifetime);
 }
开发者ID:smile-sa,项目名称:elasticsuite,代码行数:16,代码来源:Cache.php

示例4: _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

示例5: 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

示例6: 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

示例7: 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

示例8: save

 /**
  * {@inheritDoc}
  */
 public function save($cartId, \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage, $itemId)
 {
     $quote = $this->quoteRepository->get($cartId);
     /** @var CartItemInterface $item */
     $item = $this->getQuoteItem($cartId, $itemId);
     if ($item->getProductType() == \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL) {
         throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products'));
     }
     $giftMessage->setCustomerId($quote->getCustomer()->getId());
     $giftMessage->setGiftMessageId(rand());
     $msgCacheId = $itemId . self::CACHE_ID_POSTFIX;
     $this->cache->save(serialize($giftMessage), $msgCacheId);
     return true;
 }
开发者ID:marcinNS,项目名称:magento2-samples,代码行数:17,代码来源:ItemRepository.php

示例9: _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

示例10: save

 /**
  * {@inheritDoc}
  */
 public function save($cartId, \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage)
 {
     /** @var CartInterface $quote */
     $quote = $this->quoteRepository->get($cartId);
     if (0 == $quote->getItemsCount()) {
         throw new InputException(__('Gift Messages is not applicable for empty cart'));
     }
     if ($quote->getIsVirtual()) {
         throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products'));
     }
     $giftMessage->setCustomerId($quote->getCustomer()->getId());
     $giftMessage->setGiftMessageId(rand());
     $msgCacheId = $cartId . self::CACHE_ID_POSTFIX;
     $this->cache->save(serialize($giftMessage), $msgCacheId);
     return true;
 }
开发者ID:luo3555,项目名称:magento2-samples,代码行数:19,代码来源:CartRepository.php

示例11: setCachedQuotes

 /**
  * Sets received carrier quotes to cache
  *
  * @param string|array $requestParams
  * @param string $response
  * @return $this
  */
 public function setCachedQuotes($requestParams, $response, $carrierCode)
 {
     $key = $this->getQuotesCacheKey($requestParams, $carrierCode);
     $this->cache->save(serialize($response), $key, [self::CACHE_TAG]);
     // self::$quotesCache[$key] = $response;
     return $this;
 }
开发者ID:shipperhq,项目名称:module-shipper,代码行数:14,代码来源:CarrierCache.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 > $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

示例13: 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

示例14: getFeeds

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

示例15: get

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


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