|
11 | 11 |
|
12 | 12 | namespace Symfony\Contracts\Cache;
|
13 | 13 |
|
| 14 | +use Psr\Cache\CacheItemInterface; |
14 | 15 | use Psr\Cache\InvalidArgumentException;
|
15 | 16 |
|
16 | 17 | /**
|
17 |
| - * Gets/Stores items from/to a cache. |
18 |
| - * |
19 |
| - * On cache misses, a callback is called that should return the missing value. |
20 |
| - * This callback is given an ItemInterface object corresponding to the needed key, |
21 |
| - * that could be used e.g. for expiration control. |
| 18 | + * Covers most simple to advanced caching needs. |
22 | 19 | *
|
23 | 20 | * @author Nicolas Grekas <p@tchwork.com>
|
24 | 21 | */
|
25 | 22 | interface CacheInterface
|
26 | 23 | {
|
27 | 24 | /**
|
28 |
| - * @param string $key The key of the item to retrieve from the cache |
29 |
| - * @param callable(ItemInterface):mixed $callback Should return the computed value for the given key/item |
30 |
| - * @param float|null $beta A float that, as it grows, controls the likeliness of triggering |
31 |
| - * early expiration. 0 disables it, INF forces immediate expiration. |
32 |
| - * The default (or providing null) is implementation dependent but should |
33 |
| - * typically be 1.0, which should provide optimal stampede protection. |
34 |
| - * See https://en.wikipedia.org/wiki/Cache_stampede#Probabilistic_early_expiration |
| 25 | + * Fetches a value from the pool or computes it if not found. |
| 26 | + * |
| 27 | + * On cache misses, a callback is called that should return the missing value. |
| 28 | + * This callback is given a PSR-6 CacheItemInterface instance corresponding to the |
| 29 | + * requested key, that could be used e.g. for expiration control. It could also |
| 30 | + * be an ItemInterface instance when its additional features are needed. |
| 31 | + * |
| 32 | + * @param string $key The key of the item to retrieve from the cache |
| 33 | + * @param callable(CacheItemInterface):mixed $callback Should return the computed value for the given key/item |
| 34 | + * @param float|null $beta A float that, as it grows, controls the likeliness of triggering |
| 35 | + * early expiration. 0 disables it, INF forces immediate expiration. |
| 36 | + * The default (or providing null) is implementation dependent but should |
| 37 | + * typically be 1.0, which should provide optimal stampede protection. |
| 38 | + * See https://en.wikipedia.org/wiki/Cache_stampede#Probabilistic_early_expiration |
35 | 39 | *
|
36 | 40 | * @return mixed The value corresponding to the provided key
|
37 | 41 | *
|
38 | 42 | * @throws InvalidArgumentException When $key is not valid or when $beta is negative
|
39 | 43 | */
|
40 | 44 | public function get(string $key, callable $callback, float $beta = null);
|
| 45 | + |
| 46 | + /** |
| 47 | + * Removes an item from the pool. |
| 48 | + * |
| 49 | + * @param string $key The key to delete |
| 50 | + * |
| 51 | + * @throws InvalidArgumentException When $key is not valid |
| 52 | + * |
| 53 | + * @return bool True if the item was successfully removed, false if there was any error |
| 54 | + */ |
| 55 | + public function delete(string $key): bool; |
41 | 56 | }
|
0 commit comments