CacheItemPoolInterface.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace Psr\Cache;
  3. /**
  4. * CacheItemPoolInterface generates CacheItemInterface objects.
  5. *
  6. * The primary purpose of Cache\CacheItemPoolInterface is to accept a key from
  7. * the Calling Library and return the associated Cache\CacheItemInterface object.
  8. * It is also the primary point of interaction with the entire cache collection.
  9. * All configuration and initialization of the Pool is left up to an
  10. * Implementing Library.
  11. */
  12. interface CacheItemPoolInterface
  13. {
  14. /**
  15. * Returns a Cache Item representing the specified key.
  16. *
  17. * This method must always return a CacheItemInterface object, even in case of
  18. * a cache miss. It MUST NOT return null.
  19. *
  20. * @param string $key
  21. * The key for which to return the corresponding Cache Item.
  22. *
  23. * @throws InvalidArgumentException
  24. * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
  25. * MUST be thrown.
  26. *
  27. * @return CacheItemInterface
  28. * The corresponding Cache Item.
  29. */
  30. public function getItem(string $key): CacheItemInterface;
  31. /**
  32. * Returns a traversable set of cache items.
  33. *
  34. * @param string[] $keys
  35. * An indexed array of keys of items to retrieve.
  36. *
  37. * @throws InvalidArgumentException
  38. * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
  39. * MUST be thrown.
  40. *
  41. * @return iterable
  42. * An iterable collection of Cache Items keyed by the cache keys of
  43. * each item. A Cache item will be returned for each key, even if that
  44. * key is not found. However, if no keys are specified then an empty
  45. * traversable MUST be returned instead.
  46. */
  47. public function getItems(array $keys = []): iterable;
  48. /**
  49. * Confirms if the cache contains specified cache item.
  50. *
  51. * Note: This method MAY avoid retrieving the cached value for performance reasons.
  52. * This could result in a race condition with CacheItemInterface::get(). To avoid
  53. * such situation use CacheItemInterface::isHit() instead.
  54. *
  55. * @param string $key
  56. * The key for which to check existence.
  57. *
  58. * @throws InvalidArgumentException
  59. * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
  60. * MUST be thrown.
  61. *
  62. * @return bool
  63. * True if item exists in the cache, false otherwise.
  64. */
  65. public function hasItem(string $key): bool;
  66. /**
  67. * Deletes all items in the pool.
  68. *
  69. * @return bool
  70. * True if the pool was successfully cleared. False if there was an error.
  71. */
  72. public function clear(): bool;
  73. /**
  74. * Removes the item from the pool.
  75. *
  76. * @param string $key
  77. * The key to delete.
  78. *
  79. * @throws InvalidArgumentException
  80. * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
  81. * MUST be thrown.
  82. *
  83. * @return bool
  84. * True if the item was successfully removed. False if there was an error.
  85. */
  86. public function deleteItem(string $key): bool;
  87. /**
  88. * Removes multiple items from the pool.
  89. *
  90. * @param string[] $keys
  91. * An array of keys that should be removed from the pool.
  92. *
  93. * @throws InvalidArgumentException
  94. * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
  95. * MUST be thrown.
  96. *
  97. * @return bool
  98. * True if the items were successfully removed. False if there was an error.
  99. */
  100. public function deleteItems(array $keys): bool;
  101. /**
  102. * Persists a cache item immediately.
  103. *
  104. * @param CacheItemInterface $item
  105. * The cache item to save.
  106. *
  107. * @return bool
  108. * True if the item was successfully persisted. False if there was an error.
  109. */
  110. public function save(CacheItemInterface $item): bool;
  111. /**
  112. * Sets a cache item to be persisted later.
  113. *
  114. * @param CacheItemInterface $item
  115. * The cache item to save.
  116. *
  117. * @return bool
  118. * False if the item could not be queued or if a commit was attempted and failed. True otherwise.
  119. */
  120. public function saveDeferred(CacheItemInterface $item): bool;
  121. /**
  122. * Persists any deferred cache items.
  123. *
  124. * @return bool
  125. * True if all not-yet-saved items were successfully saved or there were none. False otherwise.
  126. */
  127. public function commit(): bool;
  128. }