WP_AI_Client_Cache
- Since
- 7.0.0
- Source
wp-includes/ai-client/adapters/class-wp-ai-client-cache.php:22
WordPress-specific PSR-16 cache adapter for the AI Client.
Description
Bridges PSR-16 cache operations to WordPress object cache functions, enabling the AI client to leverage WordPress caching infrastructure.
Compatibility
- WordPress
- since 7.0.0
- 6.7.10
- 6.8.11
- 6.9.10
- 7.0.7
- 7.1.3
Present in 2 of the 5 tracked releases, added in 7.0.0.
Methods · 10
- get()Fetches a value from the cache.
- set()Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
- delete()Delete an item from the cache by its unique key.
- clear()Wipes clean the entire cache's keys.
- getMultiple()Obtains multiple cache items by their unique keys.
- setMultiple()Persists a set of key => value pairs in the cache, with an optional TTL.
- deleteMultiple()Deletes multiple cache items in a single operation.
- has()Determines whether an item is present in the cache.
- ttl_to_seconds()Converts a PSR-16 TTL value to seconds for WordPress cache functions.
- iterable_to_array()Converts an iterable to an array.
Source code
class WP_AI_Client_Cache implements CacheInterface { /** * Cache group used for all cache operations. * * @since 7.0.0 * @var string */ private const CACHE_GROUP = 'wp_ai_client'; /** * Fetches a value from the cache. * * @since 7.0.0 * * @param string $key The unique key of this item in the cache. * @param mixed $default_value Default value to return if the key does not exist. * @return mixed The value of the item from the cache, or $default_value in case of cache miss. */ public function get( $key, $default_value = null ) { $found = false; $value = wp_cache_get( $key, self::CACHE_GROUP, false, $found ); if ( ! $found ) { return $default_value; } return $value; } /** * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time. * * @since 7.0.0 * * @param string $key The key of the item to store. * @param mixed $value The value of the item to store, must be serializable. * @param null|int|DateInterval $ttl Optional. The TTL value of this item. * @return bool True on success and false on failure. */ public function set( $key, $value, $ttl = null ): bool { $expire = $this->ttl_to_seconds( $ttl ); return wp_cache_set( $key, $value, self::CACHE_GROUP, $expire ); } /** * Delete an item from the cache by its unique key. * * @since 7.0.0 * * @param string $key The unique cache key of the item to delete. * @return bool True if the item was successfully removed. False if there was an error. */ public function delete( $key ): bool { return wp_cache_delete( $key, self::CACHE_GROUP ); } /** * Wipes clean the entire cache's keys. * * This method only clears the cache group used by this adapter. If the underlying * cache implementation does not support group flushing, this method returns false. * * @since 7.0.0 * * @return bool True on success and false on failure. */ public function clear(): bool { if ( ! function_exists( 'wp_cache_supports' ) || ! wp_cache_supports( 'flush_group' ) ) { return false; } return wp_cache_flush_group( self::CACHE_GROUP ); } /** * Obtains multiple cache items by their unique keys. * * @since 7.0.0Changelog
Introduced in 7.0.0. One change between 7.0.7 and 7.1.3.
Signature, return type and hooks compared across 2 parsed releases.
7.1.3
Method
get_cache_group() added.verified against source7.0.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.7 tag, from
src/wp-includes/ai-client/adapters/class-wp-ai-client-cache.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.