NullAdapter.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Cache\Adapter;
  11. use Psr\Cache\CacheItemInterface;
  12. use Symfony\Component\Cache\CacheItem;
  13. /**
  14. * @author Titouan Galopin <galopintitouan@gmail.com>
  15. */
  16. class NullAdapter implements AdapterInterface
  17. {
  18. private $createCacheItem;
  19. public function __construct()
  20. {
  21. $this->createCacheItem = \Closure::bind(
  22. function ($key) {
  23. $item = new CacheItem();
  24. $item->key = $key;
  25. $item->isHit = false;
  26. return $item;
  27. },
  28. $this,
  29. CacheItem::class
  30. );
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function getItem($key)
  36. {
  37. $f = $this->createCacheItem;
  38. return $f($key);
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function getItems(array $keys = [])
  44. {
  45. return $this->generateItems($keys);
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function hasItem($key)
  51. {
  52. return false;
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. public function clear()
  58. {
  59. return true;
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function deleteItem($key)
  65. {
  66. return true;
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public function deleteItems(array $keys)
  72. {
  73. return true;
  74. }
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public function save(CacheItemInterface $item)
  79. {
  80. return false;
  81. }
  82. /**
  83. * {@inheritdoc}
  84. */
  85. public function saveDeferred(CacheItemInterface $item)
  86. {
  87. return false;
  88. }
  89. /**
  90. * {@inheritdoc}
  91. */
  92. public function commit()
  93. {
  94. return false;
  95. }
  96. private function generateItems(array $keys)
  97. {
  98. $f = $this->createCacheItem;
  99. foreach ($keys as $key) {
  100. yield $key => $f($key);
  101. }
  102. }
  103. }