CacheItemPoolInterface.php 4.3 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($key);
  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 array|\Traversable
  42. * A traversable 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 = array());
  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($key);
  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();
  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($key);
  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. * @throws InvalidArgumentException
  93. * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
  94. * MUST be thrown.
  95. *
  96. * @return bool
  97. * True if the items were successfully removed. False if there was an error.
  98. */
  99. public function deleteItems(array $keys);
  100. /**
  101. * Persists a cache item immediately.
  102. *
  103. * @param CacheItemInterface $item
  104. * The cache item to save.
  105. *
  106. * @return bool
  107. * True if the item was successfully persisted. False if there was an error.
  108. */
  109. public function save(CacheItemInterface $item);
  110. /**
  111. * Sets a cache item to be persisted later.
  112. *
  113. * @param CacheItemInterface $item
  114. * The cache item to save.
  115. *
  116. * @return bool
  117. * False if the item could not be queued or if a commit was attempted and failed. True otherwise.
  118. */
  119. public function saveDeferred(CacheItemInterface $item);
  120. /**
  121. * Persists any deferred cache items.
  122. *
  123. * @return bool
  124. * True if all not-yet-saved items were successfully saved or there were none. False otherwise.
  125. */
  126. public function commit();
  127. }