當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。