Proxy.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\App\Cache;
  7. use \Magento\Framework\App\CacheInterface;
  8. use \Magento\Framework\ObjectManager\NoninterceptableInterface;
  9. /**
  10. * System cache proxy model
  11. */
  12. class Proxy implements
  13. CacheInterface,
  14. NoninterceptableInterface
  15. {
  16. /**
  17. * @var \Magento\Framework\ObjectManagerInterface
  18. */
  19. protected $_objectManager;
  20. /**
  21. * @var CacheInterface
  22. */
  23. protected $_cache;
  24. /**
  25. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  26. */
  27. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
  28. {
  29. $this->_objectManager = $objectManager;
  30. }
  31. /**
  32. * Create cache model
  33. *
  34. * @return CacheInterface
  35. */
  36. protected function _getCache()
  37. {
  38. if (null == $this->_cache) {
  39. $this->_cache = $this->_objectManager->get(\Magento\Framework\App\Cache::class);
  40. }
  41. return $this->_cache;
  42. }
  43. /**
  44. * Get cache frontend API object
  45. *
  46. * @return \Zend_Cache_Core
  47. */
  48. public function getFrontend()
  49. {
  50. return $this->_getCache()->getFrontend();
  51. }
  52. /**
  53. * Load data from cache by id
  54. *
  55. * @param string $identifier
  56. * @return string
  57. */
  58. public function load($identifier)
  59. {
  60. return $this->_getCache()->load($identifier);
  61. }
  62. /**
  63. * Save data
  64. *
  65. * @param string $data
  66. * @param string $identifier
  67. * @param array $tags
  68. * @param int $lifeTime
  69. * @return bool
  70. */
  71. public function save($data, $identifier, $tags = [], $lifeTime = null)
  72. {
  73. return $this->_getCache()->save($data, $identifier, $tags, $lifeTime);
  74. }
  75. /**
  76. * Remove cached data by identifier
  77. *
  78. * @param string $identifier
  79. * @return bool
  80. */
  81. public function remove($identifier)
  82. {
  83. return $this->_getCache()->remove($identifier);
  84. }
  85. /**
  86. * Clean cached data by specific tag
  87. *
  88. * @param array $tags
  89. * @return bool
  90. */
  91. public function clean($tags = [])
  92. {
  93. return $this->_getCache()->clean($tags);
  94. }
  95. }