CacheItemPoolInterface.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. */
  13. interface CacheItemPoolInterface
  14. {
  15. /**
  16. * Returns a Cache Item representing the specified key.
  17. *
  18. * This method must always return a CacheItemInterface object, even in case of
  19. * a cache miss. It MUST NOT return null.
  20. *
  21. * @param string $key
  22. * The key for which to return the corresponding Cache Item.
  23. *
  24. * @throws InvalidArgumentException
  25. * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
  26. * MUST be thrown.
  27. *
  28. * @return CacheItemInterface
  29. * The corresponding Cache Item.
  30. */
  31. public function getItem($key);
  32. /**
  33. * Returns a traversable set of cache items.
  34. *
  35. * @param array $keys
  36. * An indexed array of keys of items to retrieve.
  37. *
  38. * @throws InvalidArgumentException
  39. * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
  40. * MUST be thrown.
  41. *
  42. * @return array|\Traversable
  43. * A traversable collection of Cache Items keyed by the cache keys of
  44. * each item. A Cache item will be returned for each key, even if that
  45. * key is not found. However, if no keys are specified then an empty
  46. * traversable MUST be returned instead.
  47. */
  48. public function getItems(array $keys = array());
  49. /**
  50. * Confirms if the cache contains specified cache item.
  51. *
  52. * Note: This method MAY avoid retrieving the cached value for performance reasons.
  53. * This could result in a race condition with CacheItemInterface::get(). To avoid
  54. * such situation use CacheItemInterface::isHit() instead.
  55. *
  56. * @param string $key
  57. * The key for which to check existence.
  58. *
  59. * @throws InvalidArgumentException
  60. * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
  61. * MUST be thrown.
  62. *
  63. * @return bool
  64. * True if item exists in the cache, false otherwise.
  65. */
  66. public function hasItem($key);
  67. /**
  68. * Deletes all items in the pool.
  69. *
  70. * @return bool
  71. * True if the pool was successfully cleared. False if there was an error.
  72. */
  73. public function clear();
  74. /**
  75. * Removes the item from the pool.
  76. *
  77. * @param string $key
  78. * The key for which to delete
  79. *
  80. * @throws InvalidArgumentException
  81. * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
  82. * MUST be thrown.
  83. *
  84. * @return bool
  85. * True if the item was successfully removed. False if there was an error.
  86. */
  87. public function deleteItem($key);
  88. /**
  89. * Removes multiple items from the pool.
  90. *
  91. * @param array $keys
  92. * An array of keys that should be removed from the pool.
  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);
  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);
  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);
  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();
  128. }