Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FrontendPool.php
Go to the documentation of this file.
1 <?php
7 
10 
18 {
22  const KEY_CACHE_TYPE = 'type';
23 
27  const KEY_FRONTEND_CACHE = 'frontend';
28 
32  const KEY_CACHE = 'cache';
33 
37  private $_objectManager;
38 
42  private $deploymentConfig;
43 
47  private $_frontendPool;
48 
52  private $_typeFrontendMap;
53 
57  private $_instances = [];
58 
65  public function __construct(
67  \Magento\Framework\App\DeploymentConfig $deploymentConfig,
68  \Magento\Framework\App\Cache\Frontend\Pool $frontendPool,
69  array $typeFrontendMap = []
70  ) {
71  $this->_objectManager = $objectManager;
72  $this->deploymentConfig = $deploymentConfig;
73  $this->_frontendPool = $frontendPool;
74  $this->_typeFrontendMap = $typeFrontendMap;
75  }
76 
83  public function get($cacheType)
84  {
85  if (!isset($this->_instances[$cacheType])) {
86  $frontendId = $this->_getCacheFrontendId($cacheType);
87  $frontendInstance = $this->_frontendPool->get($frontendId);
89  $frontendInstance = $this->_objectManager->create(
90  \Magento\Framework\App\Cache\Type\AccessProxy::class,
91  ['frontend' => $frontendInstance, 'identifier' => $cacheType]
92  );
93  $this->_instances[$cacheType] = $frontendInstance;
94  }
95  return $this->_instances[$cacheType];
96  }
97 
104  protected function _getCacheFrontendId($cacheType)
105  {
106  $result = null;
107  $cacheInfo = $this->deploymentConfig->getConfigData(self::KEY_CACHE);
108  if (null !== $cacheInfo) {
109  $result = isset($cacheInfo[self::KEY_CACHE_TYPE][$cacheType][self::KEY_FRONTEND_CACHE]) ?
110  $cacheInfo[self::KEY_CACHE_TYPE][$cacheType][self::KEY_FRONTEND_CACHE] : null;
111  }
112  if (!$result) {
113  if (isset($this->_typeFrontendMap[$cacheType])) {
114  $result = $this->_typeFrontendMap[$cacheType];
115  } else {
117  }
118  }
119  return $result;
120  }
121 }
$objectManager
Definition: bootstrap.php:17
$deploymentConfig
__construct(\Magento\Framework\ObjectManagerInterface $objectManager, \Magento\Framework\App\DeploymentConfig $deploymentConfig, \Magento\Framework\App\Cache\Frontend\Pool $frontendPool, array $typeFrontendMap=[])