CacheEngine.php
3 years ago
CacheException.php
3 years ago
ObjectCache.php
3 years ago
WpCacheEngine.php
3 years ago
CacheEngine.php
45 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Caching; |
| 4 | |
| 5 | /** |
| 6 | * Interface for cache engines used by objects inheriting from ObjectCache. |
| 7 | * Here "object" means either an array or an actual PHP object. |
| 8 | */ |
| 9 | interface CacheEngine { |
| 10 | |
| 11 | /** |
| 12 | * Retrieves an object cached under a given key. |
| 13 | * |
| 14 | * @param string $key They key under which the object to retrieve is cached. |
| 15 | * @return array|object|null The cached object, or null if there's no object cached under the passed key. |
| 16 | */ |
| 17 | public function get_cached_object( string $key); |
| 18 | |
| 19 | /** |
| 20 | * Caches an object under a given key, and with a given expiration. |
| 21 | * |
| 22 | * @param string $key The key under which the object will be cached. |
| 23 | * @param array|object $object The object to cache. |
| 24 | * @param int $expiration Expiration for the cached object, in seconds. |
| 25 | * @return bool True if the object is cached successfully, false otherwise. |
| 26 | */ |
| 27 | public function cache_object( string $key, $object, int $expiration): bool; |
| 28 | |
| 29 | /** |
| 30 | * Removes a cached object from the cache. |
| 31 | * |
| 32 | * @param string $key They key under which the object is cached. |
| 33 | * @return bool True if the object is removed from the cache successfully, false otherwise (because the object wasn't cached or for other reason). |
| 34 | */ |
| 35 | public function delete_cached_object( string $key): bool; |
| 36 | |
| 37 | /** |
| 38 | * Checks if an object is cached under a given key. |
| 39 | * |
| 40 | * @param string $key The key to verify. |
| 41 | * @return bool True if there's an object cached under the given key, false otherwise. |
| 42 | */ |
| 43 | public function is_cached( string $key): bool; |
| 44 | } |
| 45 |