woocommerce_rest_api_cache_key_info
Filter the information used to generate the cache key for a REST API request.
Allows customization of what uniquely identifies a request for caching purposes.
Usage
add_filter( 'woocommerce_rest_api_cache_key_info', 'wp_kama_woocommerce_rest_api_cache_key_info_filter', 10, 5 ); /** * Function for `woocommerce_rest_api_cache_key_info` filter-hook. * * @param array $cache_key_parts Array of cache key information parts. * @param WP_REST_Request> $request The request object. * @param bool $vary_by_user Whether user ID is included in cache key. * @param string|null $endpoint_id Optional friendly identifier for the endpoint (passed to with_cache). * @param object $controller The controller instance. * * @return array */ function wp_kama_woocommerce_rest_api_cache_key_info_filter( $cache_key_parts, $request, $vary_by_user, $endpoint_id, $controller ){ // filter... return $cache_key_parts; }
- $cache_key_parts(array)
- Array of cache key information parts.
- $request(WP_REST_Request<array<string,)
- mixed>> $request The request object.
- $vary_by_user(true|false)
- Whether user ID is included in cache key.
- $endpoint_id(string|null)
- Optional friendly identifier for the endpoint (passed to with_cache).
- $controller(object)
- The controller instance.
Changelog
| Since 10.5.0 | Introduced. |
Where the hook is called
woocommerce_rest_api_cache_key_info
woocommerce/src/Internal/Traits/RestApiCache.php 937-944
$cache_key_parts = apply_filters( 'woocommerce_rest_api_cache_key_info', $cache_key_parts, $request, $vary_by_user, $endpoint_id, $this );