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