1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- /**
- * Object manager configuration cache
- *
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Framework\App\ObjectManager;
- use Magento\Framework\Serialize\SerializerInterface;
- use Magento\Framework\Serialize\Serializer\Serialize;
- class ConfigCache implements \Magento\Framework\ObjectManager\ConfigCacheInterface
- {
- /**
- * @var \Magento\Framework\Cache\FrontendInterface
- */
- protected $_cacheFrontend;
- /**
- * Cache prefix
- *
- * @var string
- */
- protected $_prefix = 'diConfig';
- /**
- * @var SerializerInterface
- */
- private $serializer;
- /**
- * @param \Magento\Framework\Cache\FrontendInterface $cacheFrontend
- */
- public function __construct(\Magento\Framework\Cache\FrontendInterface $cacheFrontend)
- {
- $this->_cacheFrontend = $cacheFrontend;
- }
- /**
- * Retrieve configuration from cache
- *
- * @param string $key
- * @return array|false
- */
- public function get($key)
- {
- $data = $this->_cacheFrontend->load($this->_prefix . $key);
- if (!$data) {
- return false;
- }
- return $this->getSerializer()->unserialize($data);
- }
- /**
- * Save config to cache
- *
- * @param array $config
- * @param string $key
- * @return void
- */
- public function save(array $config, $key)
- {
- $this->_cacheFrontend->save($this->getSerializer()->serialize($config), $this->_prefix . $key);
- }
- /**
- * Get serializer
- *
- * @return SerializerInterface
- * @deprecated 101.0.0
- */
- private function getSerializer()
- {
- if (null === $this->serializer) {
- $this->serializer = \Magento\Framework\App\ObjectManager::getInstance()->get(Serialize::class);
- }
- return $this->serializer;
- }
- }
|