> Format: $cache[$key][$id] = mixed $value; */ private static $cache = []; /** * Check whether a result has been cached for a certain utility function. * * @since 1.0.0 * * @param string $key The key to identify a particular set of results. * It is recommended to pass `__METHOD__` to this parameter. * @param int|string $id Unique identifier for these results. * It is recommended for this to be a serialization of arguments passed * to the function or an md5 hash of an input. * * @return bool */ public static function isCached($key, $id) { return self::$enabled === true && isset(self::$cache[$key]) && \array_key_exists($id, self::$cache[$key]); } /** * Retrieve a previously cached result for a certain utility function. * * @since 1.0.0 * * @param string $key The key to identify a particular set of results. * It is recommended to pass `__METHOD__` to this parameter. * @param int|string $id Unique identifier for these results. * It is recommended for this to be a serialization of arguments passed * to the function or an md5 hash of an input. * * @return mixed */ public static function get($key, $id) { if (self::$enabled === true && isset(self::$cache[$key]) && \array_key_exists($id, self::$cache[$key])) { return self::$cache[$key][$id]; } return null; } /** * Retrieve all previously cached results for a certain utility function. * * @since 1.0.0 * * @param string $key The key to identify a particular set of results. * It is recommended to pass `__METHOD__` to this parameter. * * @return array */ public static function getForKey($key) { if (self::$enabled === true && \array_key_exists($key, self::$cache)) { return self::$cache[$key]; } return []; } /** * Cache the result for a certain utility function. * * @since 1.0.0 * * @param string $key The key to identify a particular set of results. * It is recommended to pass `__METHOD__` to this parameter. * @param int|string $id Unique identifier for these results. * It is recommended for this to be a serialization of arguments passed * to the function or an md5 hash of an input. * @param mixed $value An arbitrary value to write to the cache. * * @return mixed */ public static function set($key, $id, $value) { if (self::$enabled === false) { return; } self::$cache[$key][$id] = $value; } /** * Clear the cache. * * @since 1.0.0 * * @return void */ public static function clear() { self::$cache = []; } }