From 78eb77fef6d4e8cf4affb2aa3ba2bc8418740c6c Mon Sep 17 00:00:00 2001 From: Tom Wright Date: Fri, 22 Mar 2024 12:53:13 +0000 Subject: [PATCH] Fixed generics across whole Store interface Signed-off-by: Tom Wright --- CHANGELOG.md | 2 + src/Stash/Store.php | 107 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03a7f7e..a21aeae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Fixed generics across whole Store interface + ## v0.5.2 (2024-03-22) * Added full generics to Stores diff --git a/src/Stash/Store.php b/src/Stash/Store.php index 06e3e52..3548235 100644 --- a/src/Stash/Store.php +++ b/src/Stash/Store.php @@ -12,6 +12,8 @@ use ArrayAccess; use Closure; use Countable; +use DateInterval; +use Psr\Cache\CacheItemInterface as CacheItem; use Psr\Cache\CacheItemPoolInterface as CacheItemPool; use Psr\SimpleCache\CacheInterface as SimpleCache; @@ -36,6 +38,48 @@ public function __construct( public function getNamespace(): string; public function getDriver(): Driver; + /** + * Fetches a value from the cache. + * + * @param ?T $default + * @return ?T + */ + public function get( + string $key, + mixed $default = null + ): mixed; + + /** + * Retrive item object, regardless of hit or miss + * + * @return Item + */ + public function getItem( + string $key + ): Item; + + /** + * Obtains multiple cache items by their unique keys. + * + * @param iterable $keys + * @param ?T $default + * @return iterable + */ + public function getMultiple( + iterable $keys, + mixed $default = null + ): iterable; + + /** + * Retrieve a list of items + * + * @param array $keys + * @return iterable> + */ + public function getItems( + array $keys = [] + ): iterable; + /** * @param Closure(Item, Store): T $generator * @return T @@ -45,6 +89,69 @@ public function fetch( Closure $generator ): mixed; + /** + * Determines whether an item is present in the cache. + */ + public function has( + string $key, + string ...$keys + ): bool; + + /** + * Delete an item from the cache by its unique key. + */ + public function delete( + string $key, + string ...$keys + ): bool; + + /** + * Removes the item from the pool. + */ + public function deleteItem( + string $key, + string ...$keys + ): bool; + + /** + * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time. + * + * @param T $value + */ + public function set( + string $key, + mixed $value, + int|DateInterval|null $ttl = null + ): bool; + + /** + * Persists a set of key => value pairs in the cache, with an optional TTL. + * + * @param iterable $values + */ + public function setMultiple( + iterable $values, + int|DateInterval|null $ttl = null + ): bool; + + /** + * Persists a cache item immediately. + * + * @param Item $item + */ + public function save( + CacheItem $item + ): bool; + + /** + * Sets a cache item to be persisted later. + * + * @param Item $item + */ + public function saveDeferred( + CacheItem $item + ): bool; + /** * @param T $value */