| 1 |
<?php |
| 2 |
/** |
| 3 |
* The Storage contract that storage drivers should implement. |
| 4 |
* |
| 5 |
* @package SolidWP\Performance |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types=1 ); |
| 9 |
|
| 10 |
namespace SolidWP\Performance\Storage\Contracts; |
| 11 |
|
| 12 |
use Closure; |
| 13 |
use SolidWP\Performance\Storage\Exceptions\InvalidKeyException; |
| 14 |
|
| 15 |
/** |
| 16 |
* The Storage contract that storage drivers should implement. |
| 17 |
* |
| 18 |
* @package SolidWP\Performance |
| 19 |
*/ |
| 20 |
interface Storage { |
| 21 |
|
| 22 |
/** |
| 23 |
* Put a value in storage. |
| 24 |
* |
| 25 |
* @param string|int|float|mixed[]|object $key The storage key. Accepts any variable that can be json encoded. |
| 26 |
* @param mixed $value The value to store. |
| 27 |
* @param int $expire The storage lifespan in seconds. |
| 28 |
* |
| 29 |
* @throws InvalidKeyException If passed an invalid storage key. |
| 30 |
*/ |
| 31 |
public function set( $key, $value, int $expire = 0 ): bool; |
| 32 |
|
| 33 |
/** |
| 34 |
* Get a value from storage. |
| 35 |
* |
| 36 |
* @param string|int|float|mixed[]|object $key The storage key. Accepts any variable that can be json encoded. |
| 37 |
* |
| 38 |
* @throws InvalidKeyException If passed an invalid storage key. |
| 39 |
* |
| 40 |
* @return null|mixed Returns null if we can't find the storage value. |
| 41 |
*/ |
| 42 |
public function get( $key ); |
| 43 |
|
| 44 |
/** |
| 45 |
* Delete a value from storage. |
| 46 |
* |
| 47 |
* @param string|int|float|mixed[]|object $key The storage key. |
| 48 |
* |
| 49 |
* @throws InvalidKeyException If passed an invalid storage key. |
| 50 |
*/ |
| 51 |
public function delete( $key ): bool; |
| 52 |
|
| 53 |
/** |
| 54 |
* Get an item from storage, or execute the given Closure and store the result. |
| 55 |
* |
| 56 |
* @param string|int|float|mixed[]|object $key The storage key. |
| 57 |
* @param Closure $callback The callback used to generate and store the value. |
| 58 |
* @param int $expire The storage lifespan in seconds. |
| 59 |
* |
| 60 |
* @throws InvalidKeyException If passed an invalid storage key. |
| 61 |
* |
| 62 |
* @return mixed The storage value. |
| 63 |
*/ |
| 64 |
public function remember( $key, Closure $callback, int $expire = 0 ); |
| 65 |
|
| 66 |
/** |
| 67 |
* Retrieve an item from storage and delete it. |
| 68 |
* |
| 69 |
* @param string|int|float|mixed[]|object $key The storage key. |
| 70 |
* |
| 71 |
* @throws InvalidKeyException If passed an invalid storage key. |
| 72 |
*/ |
| 73 |
public function pull( $key ); |
| 74 |
} |
| 75 |
|