/** * Retrieve cache frontend instance being decorated * * @return \Magento\Framework\Cache\FrontendInterface */ protected function _getFrontend() { $frontend = parent::_getFrontend(); if (!$frontend) { $frontend = $this->cacheFrontendPool->get(self::TYPE_IDENTIFIER); $this->setFrontend($frontend); } return $frontend; }
/** * Returns a frontend on a first call to frontend interface methods * * @SuppressWarnings(PHPMD.CamelCaseMethodName) * * @return FrontendInterface */ protected function _getFrontend() { // @codingStandardsIgnoreEnd $frontend = parent::_getFrontend(); if ($frontend === null) { $frontend = $this->frontendPool->get(self::CACHE_TYPE); } return $frontend; }
/** * @param string|null $fixtureSegment * @param string $inputCacheType * @param string $expectedFrontendId * * @dataProvider getDataProvider */ public function testGet($fixtureSegment, $inputCacheType, $expectedFrontendId) { $this->_deploymentConfig->expects($this->once())->method('getSegment')->with(\Magento\Framework\App\DeploymentConfig\CacheConfig::CONFIG_KEY)->will($this->returnValue($fixtureSegment)); $cacheFrontend = $this->getMock('Magento\\Framework\\Cache\\FrontendInterface'); $this->_cachePool->expects($this->once())->method('get')->with($expectedFrontendId)->will($this->returnValue($cacheFrontend)); $accessProxy = $this->getMock('Magento\\Framework\\App\\Cache\\Type\\AccessProxy', [], [], '', false); $this->_objectManager->expects($this->once())->method('create')->with('Magento\\Framework\\App\\Cache\\Type\\AccessProxy', $this->identicalTo(['frontend' => $cacheFrontend, 'identifier' => $inputCacheType]))->will($this->returnValue($accessProxy)); $this->assertSame($accessProxy, $this->_model->get($inputCacheType)); // Result has to be cached in memory $this->assertSame($accessProxy, $this->_model->get($inputCacheType)); }
/** * @param string|null $fixtureFrontendId * @param string $inputCacheType * @param string $expectedFrontendId * * @dataProvider getDataProvider */ public function testGet($fixtureFrontendId, $inputCacheType, $expectedFrontendId) { $this->_arguments->expects($this->once())->method('getCacheTypeFrontendId')->with($inputCacheType)->will($this->returnValue($fixtureFrontendId)); $cacheFrontend = $this->getMock('Magento\\Framework\\Cache\\FrontendInterface'); $this->_cachePool->expects($this->once())->method('get')->with($expectedFrontendId)->will($this->returnValue($cacheFrontend)); $accessProxy = $this->getMock('Magento\\Framework\\App\\Cache\\Type\\AccessProxy', array(), array(), '', false); $this->_objectManager->expects($this->once())->method('create')->with('Magento\\Framework\\App\\Cache\\Type\\AccessProxy', $this->identicalTo(array('frontend' => $cacheFrontend, 'identifier' => $inputCacheType)))->will($this->returnValue($accessProxy)); $this->assertSame($accessProxy, $this->_model->get($inputCacheType)); // Result has to be cached in memory $this->assertSame($accessProxy, $this->_model->get($inputCacheType)); }
/** * Flushes specified cache storages * * @param string[] $types * @return void */ public function flush(array $types) { $flushedBackend = []; foreach ($types as $type) { $backend = $this->pool->get($type)->getBackend(); if (in_array($backend, $flushedBackend, true)) { // it was already flushed from another frontend continue; } $backend->clean(); $flushedBackend[] = $backend; } }
/** * @param \Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool */ public function __construct(\Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool) { parent::__construct($cacheFrontendPool->get(self::TYPE_IDENTIFIER), self::CACHE_TAG); }
/** * Constructor * * @param FrontendPool $cacheFrontendPool */ public function __construct(FrontendPool $cacheFrontendPool) { parent::__construct($cacheFrontendPool->get(self::TYPE_IDENTIFIER), self::CACHE_TAG); }
/** * @param \Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool * @param StoreManagerInterface $storeManager * @param UserContextInterface $userContext */ public function __construct(\Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool, StoreManagerInterface $storeManager, UserContextInterface $userContext) { $this->storeManager = $storeManager; $this->userContext = $userContext; parent::__construct($cacheFrontendPool->get(self::TYPE_IDENTIFIER), self::CACHE_TAG); }
function it_creates_frontend_instance_via_pool_on_first_interaction(FrontendPool $pool, FrontendInterface $cacheFrontend) { $pool->get('psr6')->willReturn($cacheFrontend)->shouldBeCalled(); $cacheFrontend->load('test_key1')->willReturn('123123'); $this->load('test_key1')->shouldReturn('123123'); }
/** * @param \Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool * @param \Magento\Framework\Event\ManagerInterface $eventManager */ public function __construct(\Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool, \Magento\Framework\Event\ManagerInterface $eventManager) { parent::__construct($cacheFrontendPool->get(self::TYPE_IDENTIFIER), self::CACHE_TAG); $this->eventManager = $eventManager; }