Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * @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));
 }
Ejemplo n.º 4
0
 /**
  * @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));
 }
Ejemplo n.º 5
0
 /**
  * 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;
     }
 }
Ejemplo n.º 6
0
 /**
  * Test flushing all cache types
  *
  * Emulates situation when some cache frontends reuse the same backend
  * Asserts that the flush is invoked only once per affected storage
  */
 public function testFlushAll()
 {
     $cacheTypes = ['foo', 'bar', 'baz'];
     $frontendFoo = $this->getMockForAbstractClass('Magento\\Framework\\Cache\\FrontendInterface');
     $frontendBar = $this->getMockForAbstractClass('Magento\\Framework\\Cache\\FrontendInterface');
     $frontendBaz = $this->getMockForAbstractClass('Magento\\Framework\\Cache\\FrontendInterface');
     $this->frontendPool->expects($this->exactly(3))->method('get')->will($this->returnValueMap([['foo', $frontendFoo], ['bar', $frontendBar], ['baz', $frontendBaz]]));
     $backendOne = $this->getMockForAbstractClass('Zend_Cache_Backend_Interface');
     $backendTwo = $this->getMockForAbstractClass('Zend_Cache_Backend_Interface');
     $frontendFoo->expects($this->once())->method('getBackend')->willReturn($backendOne);
     $frontendBar->expects($this->once())->method('getBackend')->willReturn($backendOne);
     $frontendBaz->expects($this->once())->method('getBackend')->willReturn($backendTwo);
     $backendOne->expects($this->once())->method('clean');
     $backendTwo->expects($this->once())->method('clean');
     $this->model->flush($cacheTypes);
 }
Ejemplo n.º 7
0
 /**
  * @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);
 }
Ejemplo n.º 8
0
 /**
  * Constructor
  *
  * @param FrontendPool $cacheFrontendPool
  */
 public function __construct(FrontendPool $cacheFrontendPool)
 {
     parent::__construct($cacheFrontendPool->get(self::TYPE_IDENTIFIER), self::CACHE_TAG);
 }
Ejemplo n.º 9
0
 /**
  * @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);
 }
Ejemplo n.º 10
0
 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');
 }
Ejemplo n.º 11
0
 /**
  * @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;
 }