[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/php-ai-client/src/Common/Traits/ -> WithDataCachingTrait.php (summary)

Trait for objects that cache data using PSR-16 cache with in-memory fallback. When a PSR-16 cache is configured via AiClient::setCache(), data is stored persistently. Otherwise, data is cached in-memory for the duration of the request.

File Size: 162 lines (5 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 7 functions

  hasCache()
  cached()
  getCache()
  setCache()
  invalidateCaches()
  clearCache()
  buildCacheKey()

Functions
Functions that are not part of a class:

hasCache(string $key)   X-Ref
Checks if a value exists in the cache.

return: bool True if the value exists in cache, false otherwise.
param: string $key The cache key suffix (will be appended to the base key).

cached(string $key, callable $callback, $ttl = null)   X-Ref
Gets a value from the cache, or computes and caches it if not present.

return: mixed The cached or computed value.
param: string                 $key      The cache key suffix (will be appended to the base key).
param: callable               $callback The callback to compute the value if not cached.
param: int|\DateInterval|null $ttl      The TTL for the cache entry, or null for default.

getCache(string $key, $default = null)   X-Ref
Gets a value from the cache.

return: mixed The cached value or the default value if not found.
param: string $key     The cache key suffix (will be appended to the base key).
param: mixed  $default The default value to return if the key does not exist.

setCache(string $key, $value, $ttl = null)   X-Ref
Sets a value in the cache.

return: bool True on success, false on failure.
param: string                $key   The cache key suffix (will be appended to the base key).
param: mixed                 $value The value to cache.
param: int|\DateInterval|null $ttl   The TTL for the cache entry, or null for default. Ignored for local cache.

invalidateCaches()   X-Ref
Invalidates all caches managed by this object.

return: void

clearCache(string $key)   X-Ref
Clears a value from the cache.

return: bool True on success, false on failure.
param: string $key The cache key suffix (will be appended to the base key).

buildCacheKey(string $key)   X-Ref
Builds the full cache key by combining the base key with the suffix.

return: string The full cache key.
param: string $key The cache key suffix.



Generated : Sat Jun 13 09:38:55 2026 Cross-referenced by PHPXref