Title: WP_REST_URL_Details_Controller::set_cache
Published: February 3, 2022
Last modified: February 24, 2026

---

# WP_REST_URL_Details_Controller::set_cache( string $key, string $data ): bool

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/set_cache/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/set_cache/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/set_cache/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/set_cache/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/set_cache/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/set_cache/?output_format=md#changelog)

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

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Utility function to cache a given data set at a given cache key.

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

 `$key`stringrequired

The cache key under which to store the value.

`$data`stringrequired

The data to be stored at the given cache key.

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

 bool True when transient set. False if not set.

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

    ```php
    private function set_cache( $key, $data = '' ) {
    	$ttl = HOUR_IN_SECONDS;

    	/**
    	 * Filters the cache expiration.
    	 *
    	 * Can be used to adjust the time until expiration in seconds for the cache
    	 * of the data retrieved for the given URL.
    	 *
    	 * @since 5.9.0
    	 *
    	 * @param int $ttl The time until cache expiration in seconds.
    	 */
    	$cache_expiration = apply_filters( 'rest_url_details_cache_expiration', $ttl );

    	return set_site_transient( $key, $data, $cache_expiration );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php#L466)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php#L466-L482)

## 󠀁[Hooks](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/set_cache/?output_format=md#hooks)󠁿

 [apply_filters( ‘rest_url_details_cache_expiration’, int $ttl )](https://developer.wordpress.org/reference/hooks/rest_url_details_cache_expiration/)

Filters the cache expiration.

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/set_cache/?output_format=md#related)󠁿

| Uses | Description | 
| [set_site_transient()](https://developer.wordpress.org/reference/functions/set_site_transient/)`wp-includes/option.php` |

Sets/updates the value of a site transient.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

| Used by | Description | 
| [WP_REST_URL_Details_Controller::parse_url_details()](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/parse_url_details/)`wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php` |

Retrieves the contents of the title tag from the HTML response.

  |

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

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

## User Contributed Notes

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