| 1 |
<?php |
| 2 |
/** |
| 3 |
* OpenStation App Framework — Cache contract. |
| 4 |
* |
| 5 |
* A best-effort key/value cache. A miss must be indistinguishable |
| 6 |
* from "never stored" — apps only ever use it to skip work they can |
| 7 |
* redo, never as storage. |
| 8 |
* |
| 9 |
* @package OpenStation |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace OpenStation\App\Contracts; |
| 13 |
|
| 14 |
// Direct access, unless a standalone host is booting on bare PHP. |
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
defined( 'OPENSTATION_STANDALONE' ) || exit; |
| 17 |
} |
| 18 |
|
| 19 |
interface Cache { |
| 20 |
|
| 21 |
/** |
| 22 |
* Read a cached value. |
| 23 |
* |
| 24 |
* @param string $key Cache key. |
| 25 |
* @param mixed $fallback Returned on a miss. |
| 26 |
* @return mixed |
| 27 |
*/ |
| 28 |
public function get( $key, $fallback = null ); |
| 29 |
|
| 30 |
/** |
| 31 |
* Store a value. |
| 32 |
* |
| 33 |
* @param string $key Cache key. |
| 34 |
* @param mixed $value Any serialisable value. |
| 35 |
* @param int $ttl Lifetime in seconds; 0 for "as long as the host keeps it". |
| 36 |
* @return void |
| 37 |
*/ |
| 38 |
public function set( $key, $value, $ttl = 0 ); |
| 39 |
|
| 40 |
/** |
| 41 |
* Forget a value. |
| 42 |
* |
| 43 |
* @param string $key Cache key. |
| 44 |
* @return void |
| 45 |
*/ |
| 46 |
public function delete( $key ); |
| 47 |
} |
| 48 |
|