CacheEngine.php
3 years ago
CacheException.php
1 year ago
CacheNameSpaceTrait.php
1 month ago
ObjectCache.php
1 year ago
WPCacheEngine.php
1 year ago
CacheEngine.php
62 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 | * @param string $group The group under which the object is cached. |
| 16 | * |
| 17 | * @return array|object|null The cached object, or null if there's no object cached under the passed key. |
| 18 | */ |
| 19 | public function get_cached_object( string $key, string $group = '' ); |
| 20 | |
| 21 | /** |
| 22 | * Caches an object under a given key, and with a given expiration. |
| 23 | * |
| 24 | * @param string $key The key under which the object will be cached. |
| 25 | * @param array|object $object The object to cache. |
| 26 | * @param int $expiration Expiration for the cached object, in seconds. |
| 27 | * @param string $group The group under which the object will be cached. |
| 28 | * |
| 29 | * @return bool True if the object is cached successfully, false otherwise. |
| 30 | */ |
| 31 | public function cache_object( string $key, $object, int $expiration, string $group = '' ): bool; |
| 32 | |
| 33 | /** |
| 34 | * Removes a cached object from the cache. |
| 35 | * |
| 36 | * @param string $key They key under which the object is cached. |
| 37 | * @param string $group The group under which the object is cached. |
| 38 | * |
| 39 | * @return bool True if the object is removed from the cache successfully, false otherwise (because the object wasn't cached or for other reason). |
| 40 | */ |
| 41 | public function delete_cached_object( string $key, string $group = '' ): bool; |
| 42 | |
| 43 | /** |
| 44 | * Checks if an object is cached under a given key. |
| 45 | * |
| 46 | * @param string $key The key to verify. |
| 47 | * @param string $group The group under which the object is cached. |
| 48 | * |
| 49 | * @return bool True if there's an object cached under the given key, false otherwise. |
| 50 | */ |
| 51 | public function is_cached( string $key, string $group = '' ): bool; |
| 52 | |
| 53 | /** |
| 54 | * Deletes all cached objects under a given group. |
| 55 | * |
| 56 | * @param string $group The group to delete. |
| 57 | * |
| 58 | * @return bool True if the group is deleted successfully, false otherwise. |
| 59 | */ |
| 60 | public function delete_cache_group( string $group = '' ): bool; |
| 61 | } |
| 62 |