FlushAllCache.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\PageCache\Observer;
  8. use Magento\Framework\App\ObjectManager;
  9. use Magento\Framework\Event\ObserverInterface;
  10. class FlushAllCache implements ObserverInterface
  11. {
  12. /**
  13. * @var \Magento\Framework\App\PageCache\Cache
  14. *
  15. * @deprecated 100.1.0
  16. */
  17. protected $_cache;
  18. /**
  19. * Application config object
  20. *
  21. * @var \Magento\PageCache\Model\Config
  22. */
  23. protected $_config;
  24. /**
  25. * @var \Magento\PageCache\Model\Cache\Type
  26. */
  27. private $fullPageCache;
  28. /**
  29. * @param \Magento\PageCache\Model\Config $config
  30. * @param \Magento\Framework\App\PageCache\Cache $cache
  31. */
  32. public function __construct(\Magento\PageCache\Model\Config $config, \Magento\Framework\App\PageCache\Cache $cache)
  33. {
  34. $this->_config = $config;
  35. $this->_cache = $cache;
  36. }
  37. /**
  38. * Flash Built-In cache
  39. * @param \Magento\Framework\Event\Observer $observer
  40. * @return void
  41. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  42. */
  43. public function execute(\Magento\Framework\Event\Observer $observer)
  44. {
  45. if ($this->_config->getType() == \Magento\PageCache\Model\Config::BUILT_IN) {
  46. $this->getCache()->clean();
  47. }
  48. }
  49. /**
  50. * TODO: Workaround to support backwards compatibility, will rework to use Dependency Injection in MAGETWO-49547
  51. *
  52. * @return \Magento\PageCache\Model\Cache\Type
  53. */
  54. private function getCache()
  55. {
  56. if (!$this->fullPageCache) {
  57. $this->fullPageCache = ObjectManager::getInstance()->get(\Magento\PageCache\Model\Cache\Type::class);
  58. }
  59. return $this->fullPageCache;
  60. }
  61. }