CacheCleaner.php 1013 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\TestFramework\Helper;
  7. use Magento\Framework\App\Cache\Frontend\Pool;
  8. /**
  9. * Helper for cleaning cache
  10. */
  11. class CacheCleaner
  12. {
  13. /**
  14. * Clean cache by specified types
  15. *
  16. * @param array $cacheTypes
  17. */
  18. public static function clean(array $cacheTypes = [])
  19. {
  20. $cachePool = self::getCachePool();
  21. foreach ($cacheTypes as $cacheType) {
  22. $cachePool->get($cacheType)->getBackend()->clean();
  23. }
  24. }
  25. /**
  26. * Clean all cache
  27. */
  28. public static function cleanAll()
  29. {
  30. $cachePool = self::getCachePool();
  31. foreach ($cachePool as $cacheType) {
  32. $cacheType->getBackend()->clean();
  33. }
  34. }
  35. /**
  36. * Get cache pool
  37. *
  38. * @return Pool
  39. */
  40. private static function getCachePool()
  41. {
  42. return Bootstrap::getObjectManager()
  43. ->get(Pool::class);
  44. }
  45. }