Cache.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Acl\Data;
  7. /**
  8. * ACL data cache layer.
  9. * @package Magento\Framework\Acl\Data
  10. */
  11. class Cache implements CacheInterface
  12. {
  13. /**
  14. * Acl Data cache tag.
  15. */
  16. const ACL_DATA_CACHE_TAG = 'acl_cache';
  17. /**
  18. * @var \Magento\Framework\Config\CacheInterface
  19. */
  20. private $cache;
  21. /**
  22. * @var \Magento\Framework\Acl\Builder
  23. */
  24. private $aclBuilder;
  25. /**
  26. * @var string
  27. */
  28. private $cacheTag;
  29. /**
  30. * Cache constructor.
  31. *
  32. * @param \Magento\Framework\Config\CacheInterface $cache
  33. * @param \Magento\Framework\Acl\Builder $aclBuilder
  34. * @param string $cacheTag
  35. */
  36. public function __construct(
  37. \Magento\Framework\Config\CacheInterface $cache,
  38. \Magento\Framework\Acl\Builder $aclBuilder,
  39. $cacheTag = self::ACL_DATA_CACHE_TAG
  40. ) {
  41. $this->cache = $cache;
  42. $this->aclBuilder = $aclBuilder;
  43. $this->cacheTag = $cacheTag;
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function test($identifier)
  49. {
  50. return $this->cache->test($identifier);
  51. }
  52. /**
  53. * {@inheritdoc}
  54. */
  55. public function load($identifier)
  56. {
  57. return $this->cache->load($identifier);
  58. }
  59. /**
  60. * {@inheritdoc}
  61. */
  62. public function save($data, $identifier, array $tags = [], $lifeTime = null)
  63. {
  64. return $this->cache->save($data, $identifier, array_merge($tags, [$this->cacheTag]), $lifeTime);
  65. }
  66. /**
  67. * {@inheritdoc}
  68. */
  69. public function remove($identifier)
  70. {
  71. return $this->cache->remove($identifier);
  72. }
  73. /**
  74. * {@inheritdoc}
  75. */
  76. public function clean($mode = \Zend_Cache::CLEANING_MODE_MATCHING_TAG, array $tags = [])
  77. {
  78. $this->aclBuilder->resetRuntimeAcl();
  79. return $this->cache->clean($mode, array_merge($tags, [$this->cacheTag]));
  80. }
  81. /**
  82. * {@inheritdoc}
  83. */
  84. public function getBackend()
  85. {
  86. return $this->cache->getBackend();
  87. }
  88. /**
  89. * {@inheritdoc}
  90. */
  91. public function getLowLevelFrontend()
  92. {
  93. return $this->cache->getLowLevelFrontend();
  94. }
  95. }