|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ProcessMaker\Cache; |
| 4 | + |
| 5 | +interface CacheInterface |
| 6 | +{ |
| 7 | + /** |
| 8 | + * Fetches a value from the cache. |
| 9 | + * |
| 10 | + * @param string $key The unique key of this item in the cache. |
| 11 | + * @param mixed $default Default value to return if the key does not exist. |
| 12 | + * |
| 13 | + * @return mixed The value of the item from the cache, or $default in case of cache miss. |
| 14 | + */ |
| 15 | + public function get(string $key, mixed $default = null): mixed; |
| 16 | + |
| 17 | + /** |
| 18 | + * Fetches a value from the cache, or stores the value from the callback if the key exists. |
| 19 | + * |
| 20 | + * @param string $key The unique key of this item in the cache. |
| 21 | + * @param callable $callback The callback that will return the value to store in the cache. |
| 22 | + * |
| 23 | + * @return mixed The value of the item from the cache, or $default in case of cache miss. |
| 24 | + * |
| 25 | + * @throws \InvalidArgumentException |
| 26 | + */ |
| 27 | + public function getOrCache(string $key, callable $callback): mixed; |
| 28 | + |
| 29 | + /** |
| 30 | + * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time. |
| 31 | + * |
| 32 | + * @param string $key The key of the item to store. |
| 33 | + * @param mixed $value The value of the item to store, must be serializable. |
| 34 | + * @param null|int|\DateInterval $ttl Optional. The TTL value of this item. If no value is sent and |
| 35 | + * the driver supports TTL then the library may set a default value |
| 36 | + * for it or let the driver take care of that. |
| 37 | + * |
| 38 | + * @return bool True on success and false on failure. |
| 39 | + */ |
| 40 | + public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool; |
| 41 | + |
| 42 | + /** |
| 43 | + * Delete an item from the cache by its unique key. |
| 44 | + * |
| 45 | + * @param string $key The unique cache key of the item to delete. |
| 46 | + * |
| 47 | + * @return bool True if the item was successfully removed. False if there was an error. |
| 48 | + */ |
| 49 | + public function delete(string $key): bool; |
| 50 | + |
| 51 | + /** |
| 52 | + * Wipes clean the entire cache's keys. |
| 53 | + * |
| 54 | + * @return bool True on success and false on failure. |
| 55 | + */ |
| 56 | + public function clear(): bool; |
| 57 | + |
| 58 | + /** |
| 59 | + * Determines whether an item is present in the cache. |
| 60 | + * |
| 61 | + * @param string $key The unique cache key of the item to check for. |
| 62 | + * |
| 63 | + * @return bool True if the item is present in the cache, false otherwise. |
| 64 | + */ |
| 65 | + public function has(string $key): bool; |
| 66 | + |
| 67 | + /** |
| 68 | + * Determines whether an item is missing from the cache. |
| 69 | + * |
| 70 | + * @param string $key The unique cache key of the item to check for. |
| 71 | + * |
| 72 | + * @return bool True if the item is missing from the cache, false otherwise. |
| 73 | + */ |
| 74 | + public function missing(string $key): bool; |
| 75 | + |
| 76 | + /** |
| 77 | + * Creates a cache key based on provided parameters |
| 78 | + * |
| 79 | + * @param array $params Key parameters |
| 80 | + * @return string Generated cache key |
| 81 | + */ |
| 82 | + public function createKey(array $params): string; |
| 83 | +} |
0 commit comments