InvalidateCache.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © 2016 Ihor Vansach (ihor@magefan.com). All rights reserved.
  4. * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
  5. *
  6. * Glory to Ukraine! Glory to the heroes!
  7. */
  8. namespace Magefan\Blog\Observer;
  9. use Magento\Framework\Event\ObserverInterface;
  10. /**
  11. * Blog observer
  12. */
  13. class InvalidateCache implements ObserverInterface
  14. {
  15. /**
  16. * @var \Magento\Framework\App\Cache\TypeListInterface
  17. */
  18. protected $_typeList;
  19. /**
  20. * Application config object
  21. *
  22. * @var \Magento\PageCache\Model\Config
  23. */
  24. protected $_config;
  25. /**
  26. * @param \Magento\PageCache\Model\Config $config
  27. * @param \Magento\Framework\App\Cache\TypeListInterface $typeList
  28. */
  29. public function __construct(
  30. \Magento\PageCache\Model\Config $config,
  31. \Magento\Framework\App\Cache\TypeListInterface $typeList
  32. ) {
  33. $this->_config = $config;
  34. $this->_typeList = $typeList;
  35. }
  36. /**
  37. * Invalidate full page and block cache
  38. *
  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->isEnabled()) {
  46. $this->_typeList->invalidate(
  47. \Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER
  48. );
  49. }
  50. $this->_typeList->invalidate(
  51. \Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER
  52. );
  53. }
  54. }