本文整理汇总了PHP中Magento\Framework\Cache\FrontendInterface::save方法的典型用法代码示例。如果您正苦于以下问题:PHP FrontendInterface::save方法的具体用法?PHP FrontendInterface::save怎么用?PHP FrontendInterface::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Cache\FrontendInterface
的用法示例。
在下文中一共展示了FrontendInterface::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: aroundDispatch
/**
* @param \Magento\Framework\App\FrontController $subject
* @param callable $proceed
* @param \Magento\Framework\App\RequestInterface $request
*
* @return \Magento\Framework\App\ResponseInterface
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundDispatch(\Magento\Framework\App\FrontController $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
{
if ($this->_appState->isInstalled() && !$this->_cache->load('data_upgrade')) {
$this->_dbUpdater->updateScheme();
$this->_dbUpdater->updateData();
$this->_cache->save('true', 'data_upgrade');
}
return $proceed($request);
}
示例2: aroundDispatch
/**
* @param \Magento\Framework\App\FrontController $subject
* @param \Closure $proceed
* @param \Magento\Framework\App\RequestInterface $request
*
* @throws \Magento\Framework\Module\Exception
* @return \Magento\Framework\App\ResponseInterface
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundDispatch(\Magento\Framework\App\FrontController $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
{
if (!$this->cache->load('db_is_up_to_date')) {
if (!$this->isDbUpToDate()) {
throw new \Magento\Framework\Module\Exception('Looks like database is outdated. Please, use setup tool to perform update');
} else {
$this->cache->save('true', 'db_is_up_to_date');
}
}
return $proceed($request);
}
示例3: fetchAll
/**
* {@inheritdoc}
*/
public function fetchAll(\Zend_Db_Select $select, array $bindParams = array())
{
$cacheId = $this->_getSelectCacheId($select);
$result = $this->_cache->load($cacheId);
if ($result) {
$result = unserialize($result);
} else {
$result = $this->_fetchStrategy->fetchAll($select, $bindParams);
$this->_cache->save(serialize($result), $cacheId, $this->_cacheTags, $this->_cacheLifetime);
}
return $result;
}
示例4: _initializeConfigList
/**
* Init cached list of validation files
*/
protected function _initializeConfigList()
{
if (!$this->_configFiles) {
$this->_configFiles = $this->cache->load(self::CACHE_KEY);
if (!$this->_configFiles) {
$this->_configFiles = $this->moduleReader->getConfigurationFiles('validation.xml');
$this->cache->save(serialize($this->_configFiles), self::CACHE_KEY);
} else {
$this->_configFiles = unserialize($this->_configFiles);
}
}
}
示例5: load
/**
* Load modules DI configuration
*
* @param string $area
* @return array
*/
public function load($area)
{
$cacheId = $area . '::DiConfig';
$data = $this->_cache->load($cacheId);
if (!$data) {
$data = $this->_reader->read($area);
$this->_cache->save(serialize($data), $cacheId);
} else {
$data = unserialize($data);
}
return $data;
}
示例6: aroundDispatch
/**
* @param \Magento\Framework\App\FrontController $subject
* @param \Closure $proceed
* @param \Magento\Framework\App\RequestInterface $request
*
* @throws \Magento\Framework\Exception\LocalizedException
* @return \Magento\Framework\App\ResponseInterface
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundDispatch(\Magento\Framework\App\FrontController $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
{
if (!$this->cache->load('db_is_up_to_date')) {
$errors = $this->dbVersionInfo->getDbVersionErrors();
if ($errors) {
$formattedErrors = $this->formatErrors($errors);
throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Please upgrade your database: Run "bin/magento setup:upgrade" from the Magento root directory.' . ' %1The following modules are outdated:%2%3', [PHP_EOL, PHP_EOL, implode(PHP_EOL, $formattedErrors)]));
} else {
$this->cache->save('true', 'db_is_up_to_date');
}
}
return $proceed($request);
}
示例7: aroundDispatch
/**
* @param \Magento\Framework\App\FrontController $subject
* @param \Closure $proceed
* @param \Magento\Framework\App\RequestInterface $request
*
* @throws \Magento\Framework\Module\Exception
* @return \Magento\Framework\App\ResponseInterface
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundDispatch(\Magento\Framework\App\FrontController $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
{
if (!$this->cache->load('db_is_up_to_date')) {
$errors = $this->dbVersionInfo->getDbVersionErrors();
if ($errors) {
$formattedErrors = $this->formatErrors($errors);
throw new \Magento\Framework\Module\Exception('Please update your database: Run "php -f index.php update" from the Magento root/setup directory.' . PHP_EOL . 'The following modules are outdated:' . PHP_EOL . implode(PHP_EOL, $formattedErrors));
} else {
$this->cache->save('true', 'db_is_up_to_date');
}
}
return $proceed($request);
}
示例8: getMethodsMap
/**
* Return service interface or Data interface methods loaded from cache
*
* @param string $interfaceName
* @return array
* <pre>
* Service methods' reflection data stored in cache as 'methodName' => 'returnType'
* ex.
* [
* 'create' => '\Magento\Customer\Api\Data\Customer',
* 'validatePassword' => 'boolean'
* ]
* </pre>
*/
public function getMethodsMap($interfaceName)
{
$key = self::SERVICE_INTERFACE_METHODS_CACHE_PREFIX . "-" . md5($interfaceName);
if (!isset($this->serviceInterfaceMethodsMap[$key])) {
$methodMap = $this->cache->load($key);
if ($methodMap) {
$this->serviceInterfaceMethodsMap[$key] = unserialize($methodMap);
} else {
$methodMap = $this->getMethodMapViaReflection($interfaceName);
$this->serviceInterfaceMethodsMap[$key] = $methodMap;
$this->cache->save(serialize($this->serviceInterfaceMethodsMap[$key]), $key);
}
}
return $this->serviceInterfaceMethodsMap[$key];
}
示例9: getScope
/**
* Retrieve config section
*
* @param string $scopeType
* @param string|\Magento\Framework\DataObject|null $scopeCode
* @return \Magento\Framework\App\Config\DataInterface
*/
public function getScope($scopeType, $scopeCode = null)
{
$scopeCode = $this->_getScopeCode($scopeType, $scopeCode);
$code = $scopeType . '|' . $scopeCode;
if (!isset($this->_scopes[$code])) {
// Key by url to support dynamic {{base_url}} and port assignments
$host = $this->getRequest()->getHttpHost();
$port = $this->getRequest()->getServer('SERVER_PORT');
$path = $this->getRequest()->getBasePath();
$urlInfo = $host . $port . trim($path, '/');
$cacheKey = $this->_cacheId . '|' . $code . '|' . $urlInfo;
$data = $this->_cache->load($cacheKey);
if ($data) {
$data = unserialize($data);
} else {
$reader = $this->_readerPool->getReader($scopeType);
if ($scopeType === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
$data = $reader->read();
} else {
$data = $reader->read($scopeCode);
}
$this->_cache->save(serialize($data), $cacheKey, [self::CACHE_TAG]);
}
$this->_scopes[$code] = $this->_dataFactory->create(['data' => $data]);
}
return $this->_scopes[$code];
}
示例10: __construct
/**
* @param \Magento\Framework\Config\ReaderInterface $reader
* @param \Magento\Framework\Config\ScopeListInterface $scopeList
* @param \Magento\Framework\Cache\FrontendInterface $cache
* @param \Magento\Framework\ObjectManager\Relations $relations
* @param \Magento\Framework\Interception\ObjectManager\Config $omConfig
* @param \Magento\Framework\ObjectManager\Definition $classDefinitions
* @param string $cacheId
*/
public function __construct(\Magento\Framework\Config\ReaderInterface $reader, \Magento\Framework\Config\ScopeListInterface $scopeList, \Magento\Framework\Cache\FrontendInterface $cache, \Magento\Framework\ObjectManager\Relations $relations, \Magento\Framework\Interception\ObjectManager\Config $omConfig, \Magento\Framework\ObjectManager\Definition $classDefinitions, $cacheId = 'interception')
{
$this->_omConfig = $omConfig;
$this->_relations = $relations;
$this->_classDefinitions = $classDefinitions;
$this->_cache = $cache;
$this->_cacheId = $cacheId;
$this->_reader = $reader;
$intercepted = $this->_cache->load($this->_cacheId);
if ($intercepted !== false) {
$this->_intercepted = unserialize($intercepted);
} else {
$config = array();
foreach ($scopeList->getAllScopes() as $scope) {
$config = array_replace_recursive($config, $this->_reader->read($scope));
}
unset($config['preferences']);
foreach ($config as $typeName => $typeConfig) {
if (!empty($typeConfig['plugins'])) {
$this->_intercepted[ltrim($typeName, '\\')] = true;
}
}
foreach ($config as $typeName => $typeConfig) {
$this->hasPlugins(ltrim($typeName, '\\'));
}
foreach ($classDefinitions->getClasses() as $class) {
$this->hasPlugins($class);
}
$this->_cache->save(serialize($this->_intercepted), $this->_cacheId);
}
}
示例11: save
/**
* Persists a cache item immediately.
*
* @param CacheItemInterface $item
* The cache item to save.
*
* @return bool
* True if the item was successfully persisted. False if there was an error.
*
* @throws InvalidArgumentException
*/
public function save(CacheItemInterface $item)
{
$expirationTime = null;
if ($item instanceof ExtractableCacheLifetimeInterface) {
$expirationTime = $item->getCacheLifetime();
}
return $this->cacheFrontend->save(serialize($item instanceof ExtractableCacheValueInterface ? $item->getCacheValue() : $item->get()), $this->prepareKey($item->getKey()), $this->tags, $expirationTime);
}
示例12: _loadTypeStatuses
/**
* Load statuses (enabled/disabled) of cache types
*
* @param bool $forceDisableAll
* @return void
*/
private function _loadTypeStatuses($forceDisableAll = false)
{
$typeOptions = $this->_cacheFrontend->load(self::CACHE_ID);
if ($typeOptions !== false) {
$typeOptions = unserialize($typeOptions);
} else {
$typeOptions = $this->_options->getAllOptions();
if ($typeOptions !== false) {
$this->_cacheFrontend->save(serialize($typeOptions), self::CACHE_ID);
}
}
if ($typeOptions) {
foreach ($typeOptions as $cacheType => $isTypeEnabled) {
$this->setEnabled($cacheType, $isTypeEnabled && !$forceDisableAll);
}
}
}
示例13: _getRoutes
/**
* Fetch routes from configs by area code and router id
*
* @param string $scope
* @return array
*/
protected function _getRoutes($scope = null)
{
$scope = $scope ?: $this->_configScope->getCurrentScope();
if (isset($this->_routes[$scope])) {
return $this->_routes[$scope];
}
$cacheId = $scope . '::' . $this->_cacheId;
$cachedRoutes = unserialize($this->_cache->load($cacheId));
if (is_array($cachedRoutes)) {
$this->_routes[$scope] = $cachedRoutes;
return $cachedRoutes;
}
$routers = $this->_reader->read($scope);
$routes = $routers[$this->_areaList->getDefaultRouter($scope)]['routes'];
$this->_cache->save(serialize($routes), $cacheId);
$this->_routes[$scope] = $routes;
return $routes;
}
示例14:
function it_commits_deferred_cache_items_only_onces(CacheItemInterface $cacheItem)
{
$cacheItem->get()->willReturn([1, 2, 3])->shouldBeCalledTimes(1);
$cacheItem->getKey()->willReturn('key1')->shouldBeCalledTimes(1);
$this->cacheFrontend->save(serialize([1, 2, 3]), 'prefix_key1', ['tag1', 'tag2'], null)->willReturn(true)->shouldBeCalledTimes(1);
$this->saveDeferred($cacheItem)->shouldReturn(true);
$this->commit()->shouldReturn(true);
// This time nothing should happen
$this->commit()->shouldReturn(true);
}
示例15: getStoresData
/**
* Get stores data
*
* @return array
*/
protected function getStoresData()
{
$cacheKey = 'resolved_stores_' . md5($this->runMode . $this->scopeCode);
$cacheData = $this->cache->load($cacheKey);
if ($cacheData) {
$storesData = unserialize($cacheData);
} else {
$storesData = $this->readStoresData();
$this->cache->save(serialize($storesData), $cacheKey, [self::CACHE_TAG]);
}
return $storesData;
}