Title: AiClient::setCache
Published: May 20, 2026

---

# AiClient::setCache( WordPressAiClientDependenciesPsrSimpleCacheCacheInterface|null $cache ): void

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wordpress-aiclient-aiclient/setcache/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wordpress-aiclient-aiclient/setcache/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wordpress-aiclient-aiclient/setcache/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-aiclient/setcache/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-aiclient/setcache/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wordpress-aiclient-aiclient/setcache/?output_format=md#wp--skip-link--target)

Sets the PSR-16 cache for storing and retrieving cached data.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wordpress-aiclient-aiclient/setcache/?output_format=md#description)󠁿

The cache can be used to store AI responses and other data to avoid redundant API
calls and improve performance.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wordpress-aiclient-aiclient/setcache/?output_format=md#parameters)󠁿

 `$cache`WordPressAiClientDependenciesPsrSimpleCacheCacheInterface|nullrequired

The PSR-16 cache instance, or null to disable caching.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wordpress-aiclient-aiclient/setcache/?output_format=md#return)󠁿

 void

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-aiclient/setcache/?output_format=md#source)󠁿

    ```php
    public static function setCache(?CacheInterface $cache): void
    {
        self::$cache = $cache;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/php-ai-client/src/aiclient.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/php-ai-client/src/AiClient.php#L151)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/php-ai-client/src/AiClient.php#L151-L154)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-aiclient/setcache/?output_format=md#changelog)󠁿

| Version | Description | 
| [0.4.0](https://developer.wordpress.org/reference/since/0.4.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwordpress-aiclient-aiclient%2Fsetcache%2F)
before being able to contribute a note or feedback.