本文整理汇总了PHP中Magento\Framework\App\CacheInterface类的典型用法代码示例。如果您正苦于以下问题:PHP CacheInterface类的具体用法?PHP CacheInterface怎么用?PHP CacheInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CacheInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Creates a currency instance.
*
* @param CacheInterface $appCache
* @param string|array $options Options array or currency short name when string is given
* @param string $locale Locale name
*/
public function __construct(CacheInterface $appCache, $options = null, $locale = null)
{
// set Zend cache to low level frontend app cache
$lowLevelFrontendCache = $appCache->getFrontend()->getLowLevelFrontend();
\Zend_Currency::setCache($lowLevelFrontendCache);
parent::__construct($options, $locale);
}
示例2: __construct
/**
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
* @param \Magento\Framework\App\CacheInterface $cache
* @param \Magento\Framework\Stdlib\DateTime $dateTime
* @param string $connectionName
*/
public function __construct(
\Magento\Framework\Model\ResourceModel\Db\Context $context,
\Magento\Framework\App\CacheInterface $cache,
\Magento\Framework\Stdlib\DateTime $dateTime,
$connectionName = null
) {
$this->dateTime = $dateTime;
parent::__construct($context, $connectionName);
$this->_cache = $cache->getFrontend();
}
示例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/']]]]]);
}
示例4: 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;
}
示例5: testCheckUpdate
/**
* @dataProvider checkUpdateDataProvider
* @param bool $callInbox
* @param string $curlRequest
*/
public function testCheckUpdate($callInbox, $curlRequest)
{
$mockName = 'Test Product Name';
$mockVersion = '0.0.0';
$mockEdition = 'Test Edition';
$mockUrl = 'http://test-url';
$this->productMetadata->expects($this->once())->method('getName')->willReturn($mockName);
$this->productMetadata->expects($this->once())->method('getVersion')->willReturn($mockVersion);
$this->productMetadata->expects($this->once())->method('getEdition')->willReturn($mockEdition);
$this->urlBuilder->expects($this->once())->method('getUrl')->with('*/*/*')->willReturn($mockUrl);
$configValues = ['timeout' => 2, 'useragent' => $mockName . '/' . $mockVersion . ' (' . $mockEdition . ')', 'referer' => $mockUrl];
$lastUpdate = 0;
$this->cacheManager->expects($this->once())->method('load')->will($this->returnValue($lastUpdate));
$this->curlFactory->expects($this->at(0))->method('create')->will($this->returnValue($this->curl));
$this->curl->expects($this->once())->method('setConfig')->with($configValues)->willReturnSelf();
$this->curl->expects($this->once())->method('read')->will($this->returnValue($curlRequest));
$this->backendConfig->expects($this->at(0))->method('getValue')->will($this->returnValue('1'));
$this->backendConfig->expects($this->once())->method('isSetFlag')->will($this->returnValue(false));
$this->backendConfig->expects($this->at(1))->method('getValue')->will($this->returnValue('http://feed.magento.com'));
$this->deploymentConfig->expects($this->once())->method('get')->with(ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE)->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC'));
if ($callInbox) {
$this->inboxFactory->expects($this->once())->method('create')->will($this->returnValue($this->inboxModel));
$this->inboxModel->expects($this->once())->method('parse')->will($this->returnSelf());
} else {
$this->inboxFactory->expects($this->never())->method('create');
$this->inboxModel->expects($this->never())->method('parse');
}
$this->feed->checkUpdate();
}
示例6: testAfterUpdateMview
/**
* Test afterUpdateMview
*
* @return void
*/
public function testAfterUpdateMview()
{
$tags = ['tag_name1', 'tag_name2'];
$this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->equalTo('clean_cache_after_reindex'), $this->equalTo(['object' => $this->contextMock]));
$this->contextMock->expects($this->atLeastOnce())->method('getIdentities')->willReturn($tags);
$this->cacheMock->expects($this->once())->method('clean')->with($tags);
$this->plugin->afterUpdateMview($this->subjectMock);
}
示例7: testGetStoreLabelsByAttributeIdWithCacheSave
public function testGetStoreLabelsByAttributeIdWithCacheSave()
{
$attributeId = 1;
$cacheId = \Magento\Eav\Plugin\Model\ResourceModel\Entity\Attribute::STORE_LABEL_ATTRIBUTE . $attributeId;
$this->cache->expects($this->any())->method('load')->with($cacheId)->willReturn(false);
$this->cache->expects($this->any())->method('save')->with(serialize([$attributeId]), $cacheId, [\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]);
$this->assertEquals([$attributeId], $this->getAttribute(true)->aroundGetStoreLabelsByAttributeId($this->subject, $this->mockPluginProceed([$attributeId]), $attributeId));
}
示例8: changeConfigs
/**
* @param array $configs
*
* @return void
*/
public function changeConfigs(array $configs)
{
foreach ($configs as $config) {
$config = array_merge($this->defaultConfig, $config);
if ($this->isValidConfig($config)) {
$this->changeConfig($config['path'], $config['value'], $config['scope_type'], $config['scope_code']);
}
}
$this->cache->clean();
}
示例9: testGetFeedsWithCache
public function testGetFeedsWithCache()
{
$dataProvider = $this->getMock('Magento\\Framework\\App\\Rss\\DataProviderInterface');
$dataProvider->expects($this->any())->method('getCacheKey')->will($this->returnValue('cache_key'));
$dataProvider->expects($this->any())->method('getCacheLifetime')->will($this->returnValue(100));
$dataProvider->expects($this->never())->method('getRssData');
$this->rss->setDataProvider($dataProvider);
$this->cacheInterface->expects($this->once())->method('load')->will($this->returnValue(serialize($this->feedData)));
$this->cacheInterface->expects($this->never())->method('save');
$this->assertEquals($this->feedData, $this->rss->getFeeds());
}
示例10: testExecuteRandom
public function testExecuteRandom()
{
$newKey = 'RSASHA9000VERYSECURESUPERMANKEY';
$this->requestMock->expects($this->at(0))->method('getPost')->with($this->equalTo('generate_random'))->willReturn(1);
$this->changeMock->expects($this->once())->method('changeEncryptionKey')->willReturn($newKey);
$this->managerMock->expects($this->once())->method('addSuccessMessage');
$this->managerMock->expects($this->once())->method('addNoticeMessage');
$this->cacheMock->expects($this->once())->method('clean');
$this->responseMock->expects($this->once())->method('setRedirect');
$this->model->execute();
}
示例11: 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;
}
示例12: testGetAttributesUsedForSortByWithCacheSave
public function testGetAttributesUsedForSortByWithCacheSave()
{
$entityTypeId = 'type';
$storeId = 'store';
$attributes = ['attributes'];
$this->subject->expects($this->any())->method('getEntityTypeId')->willReturn($entityTypeId);
$this->subject->expects($this->any())->method('getStoreId')->willReturn($storeId);
$cacheId = \Magento\Catalog\Plugin\Model\ResourceModel\Config::PRODUCT_LISTING_SORT_BY_ATTRIBUTES_CACHE_ID . $entityTypeId . '_' . $storeId;
$this->cache->expects($this->any())->method('load')->with($cacheId)->willReturn(false);
$this->cache->expects($this->any())->method('save')->with(serialize($attributes), $cacheId, [\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]);
$this->assertEquals($attributes, $this->getConfig(true)->aroundGetAttributesUsedForSortBy($this->subject, $this->mockPluginProceed($attributes)));
}
示例13: _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;
}
示例14: 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;
}
示例15: 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;
}