| 1 |
<?php |
| 2 |
/** |
| 3 |
* Cache repository interface. |
| 4 |
* |
| 5 |
* @package SeQura/WC |
| 6 |
* @subpackage SeQura/WC/Repositories |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace SeQura\WC\Repositories; |
| 10 |
|
| 11 |
/** |
| 12 |
* Provides caching capabilities with a two-level strategy: |
| 13 |
* WordPress object cache (persistent when Redis/Memcached is configured) |
| 14 |
* backed by a static in-memory array for per-request fast path. |
| 15 |
*/ |
| 16 |
interface Interface_Cache_Repository { |
| 17 |
|
| 18 |
/** |
| 19 |
* Get a value from the cache. |
| 20 |
* |
| 21 |
* @param string $key Cache key. |
| 22 |
* @param string $group Cache group. |
| 23 |
* @param bool $found Whether the key was found in the cache. Passed by reference. |
| 24 |
* Distinguishes between a cached false/0 value and a cache miss. |
| 25 |
* |
| 26 |
* @return mixed Cached value, or false on miss. |
| 27 |
*/ |
| 28 |
public function get( $key, $group, &$found = false ); |
| 29 |
|
| 30 |
/** |
| 31 |
* Set a value in the cache. |
| 32 |
* |
| 33 |
* @param string $key Cache key. |
| 34 |
* @param mixed $value Value to store. Must be serializable. |
| 35 |
* @param string $group Cache group. |
| 36 |
* @param int $ttl Time to live in seconds. 0 means no expiration (only applies to persistent backends). |
| 37 |
*/ |
| 38 |
public function set( $key, $value, $group, $ttl = 0 ): bool; |
| 39 |
|
| 40 |
/** |
| 41 |
* Delete a value from the cache. |
| 42 |
* |
| 43 |
* @param string $key Cache key. |
| 44 |
* @param string $group Cache group. |
| 45 |
*/ |
| 46 |
public function delete( $key, $group ): bool; |
| 47 |
|
| 48 |
/** |
| 49 |
* Atomically increment a numeric value in the cache. |
| 50 |
* |
| 51 |
* Uses wp_cache_incr() which is atomic on Redis/Memcached backends, |
| 52 |
* eliminating the read-then-write race of get()+set(). |
| 53 |
* If the key does not exist it is initialised to 1 with the given TTL. |
| 54 |
* |
| 55 |
* @param string $key Cache key. |
| 56 |
* @param string $group Cache group. |
| 57 |
* @param int $ttl TTL used only when the key is first created. 0 = no expiration. |
| 58 |
* |
| 59 |
* @return int New value after increment. |
| 60 |
*/ |
| 61 |
public function increment( $key, $group, $ttl = 0 ): int; |
| 62 |
|
| 63 |
/** |
| 64 |
* Flush all cached data from both the static in-memory array and the WordPress object cache. |
| 65 |
*/ |
| 66 |
public function flush(): void; |
| 67 |
} |
| 68 |
|