Skip to content

Commit

Permalink
Fixed generics across whole Store interface
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Wright <[email protected]>
  • Loading branch information
betterthanclay committed Mar 22, 2024
1 parent 51b115c commit 78eb77f
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Fixed generics across whole Store interface

## v0.5.2 (2024-03-22)
* Added full generics to Stores

Expand Down
107 changes: 107 additions & 0 deletions src/Stash/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<T>
*/
public function getItem(
string $key
): Item;

/**
* Obtains multiple cache items by their unique keys.
*
* @param iterable<int, string> $keys
* @param ?T $default
* @return iterable<string, ?T>
*/
public function getMultiple(
iterable $keys,
mixed $default = null
): iterable;

/**
* Retrieve a list of items
*
* @param array<string> $keys
* @return iterable<string, Item<T>>
*/
public function getItems(
array $keys = []
): iterable;

/**
* @param Closure(Item<T>, Store<T>): T $generator
* @return T
Expand All @@ -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<string, T> $values
*/
public function setMultiple(
iterable $values,
int|DateInterval|null $ttl = null
): bool;

/**
* Persists a cache item immediately.
*
* @param Item<T> $item
*/
public function save(
CacheItem $item
): bool;

/**
* Sets a cache item to be persisted later.
*
* @param Item<T> $item
*/
public function saveDeferred(
CacheItem $item
): bool;

/**
* @param T $value
*/
Expand Down

0 comments on commit 78eb77f

Please sign in to comment.