-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves the logic responsible for loading, saving, clearing the interception config cache into it's own class
- Loading branch information
Showing
6 changed files
with
157 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
lib/internal/Magento/Framework/Interception/Config/CacheManager.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Framework\Interception\Config; | ||
|
||
/** | ||
* Interception cache manager responsible for handling interaction with compiled and | ||
* uncompiled interception data | ||
*/ | ||
class CacheManager | ||
{ | ||
/** | ||
* @var \Magento\Framework\Cache\FrontendInterface | ||
*/ | ||
private $cache; | ||
|
||
/** | ||
* @var \Magento\Framework\Serialize\SerializerInterface | ||
*/ | ||
private $serializer; | ||
|
||
/** | ||
* @var \Magento\Framework\App\ObjectManager\ConfigWriterInterface | ||
*/ | ||
private $configWriter; | ||
|
||
/** | ||
* @var \Magento\Framework\App\ObjectManager\ConfigLoader\Compiled | ||
*/ | ||
private $compiledLoader; | ||
|
||
/** | ||
* @param \Magento\Framework\Cache\FrontendInterface $cache | ||
* @param \Magento\Framework\Serialize\SerializerInterface $serializer | ||
* @param \Magento\Framework\App\ObjectManager\ConfigWriterInterface $configWriter | ||
* @param \Magento\Framework\App\ObjectManager\ConfigLoader\Compiled $compiledLoader | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\Cache\FrontendInterface $cache, | ||
\Magento\Framework\Serialize\SerializerInterface $serializer, | ||
\Magento\Framework\App\ObjectManager\ConfigWriterInterface $configWriter, | ||
\Magento\Framework\App\ObjectManager\ConfigLoader\Compiled $compiledLoader | ||
) { | ||
$this->cache = $cache; | ||
$this->serializer = $serializer; | ||
$this->configWriter = $configWriter; | ||
$this->compiledLoader = $compiledLoader; | ||
} | ||
|
||
/** | ||
* Load the interception config from cache | ||
* | ||
* @param string $key | ||
* @return array|null | ||
*/ | ||
public function load(string $key): ?array | ||
{ | ||
if ($this->isCompiled($key)) { | ||
return $this->compiledLoader->load($key); | ||
} | ||
|
||
$intercepted = $this->cache->load($key); | ||
return $intercepted ? $this->serializer->unserialize($intercepted) : null; | ||
} | ||
|
||
/** | ||
* Save config to cache backend | ||
* | ||
* @param string $key | ||
* @param array $data | ||
*/ | ||
public function save(string $key, array $data) | ||
{ | ||
$this->cache->save($this->serializer->serialize($data), $key); | ||
} | ||
|
||
/** | ||
* Save config to filesystem | ||
* | ||
* @param string $key | ||
* @param array $data | ||
*/ | ||
public function saveCompiled(string $key, array $data) | ||
{ | ||
$this->configWriter->write($key, $data); | ||
} | ||
|
||
/** | ||
* Purge interception cache | ||
* | ||
* @param string $key | ||
*/ | ||
public function clean(string $key) | ||
{ | ||
$this->cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, [$key]); | ||
} | ||
|
||
/** | ||
* Check for the compiled config with the generated metadata | ||
* | ||
* @param string $key | ||
* @return bool | ||
*/ | ||
private function isCompiled(string $key): bool | ||
{ | ||
return file_exists(\Magento\Framework\App\ObjectManager\ConfigLoader\Compiled::getFilePath($key)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.