Description
Are you facing speed issues, using the WordPress REST API? This plugin will allow WordPress to cache the responses of the REST API, making it much faster.
This plugin offers:
- Caching of all default WordPress REST API
GET-endpoints. - Caching of (custom) post type endpoints.
- Caching of (custom) taxonomy endpoints.
- Automated flushing of caches if (some of) its contents are edited.
- Manual flushing of all caches.
- Manual flushing of specific caches.
- A counter how many times a cache has been retrieved.
- Specifying after what time the cache should be timed out.
- Registering custom endpoints for caching.
- Automatic cache regeneration.
WP REST Cache Pro
For more advanced features, check out our WP REST Cache Pro plugin:
- Configure custom endpoints for caching through the wp-admin interface.
- Configure relationships within endpoints.
- No coding required.
Installation from within WordPress
- Visit ‘Plugins > Add New’ (or ‘My Sites > Network Admin > Plugins > Add New’ if you are on a multisite installation).
- Search for ‘WP REST Cache’.
- Activate the WP REST Cache plugin through the ‘Plugins’ menu in WordPress.
- Go to “after activation” below.
Installation manually
- Upload the
wp-rest-cachefolder to the/wp-content/plugins/directory. - Activate the WP REST Cache plugin through the ‘Plugins’ menu in WordPress.
- Go to “after activation” below.
After activation
- Visit ‘Plugins > Must-Use’ (or ‘My Sites > Network Admin > Plugins > Must-Use’ if you are on a multisite installation).
- Check if the ‘WP REST Cache – Must-Use Plugin’ is there, if not copy the file
wp-rest-cache.phpfrom the/sourcesfolder of the WP REST Cache Plugin to the folder/wp-content/mu-plugins/.
Optionally:
The default timeout for caches generated by the WP REST Cache plugin is set to 1 year. If you want to change this:
- Visit ‘Settings > WP REST Cache’.
- Change the Cache timeout.
Screenshots





FAQ
I have edited a page/post, do I need to clear the cache?
No, the plugin will automatically flush all cache related to the page/post you just edited.
I have created a custom post type, will the plugin cache the custom post type endpoint?
Yes, the plugin will automatically cache the endpoint of custom post types. Unless you have created a custom WP_REST_Controller for it, then it will not automatically cache the endpoint.
I have created a custom taxonomy, will the plugin cache the taxonomy endpoint?
Yes, the plugin will automatically cache the endpoint of custom taxonomies. Unless you have created a custom WP_REST_Controller for it, then it will not automatically cache the endpoint.
I have created a custom WP REST endpoint, will the plugin cache this endpoint?
No, the plugin will not cache your custom endpoint unless you tell it to cache it using our WP REST Cache Pro plugin or the hook
wp_rest_cache/allowed_endpoints(See ‘Can I register my own endpoint for caching?’). Please keep in mind that once you do so the plugin will not automatically flush the cache of that endpoint if something is edited (it has no way of knowing when to flush the cache). It will however try to determine the relations and for the determined relations it will flush the cache automatically once the relation is edited.Can I register my own endpoint for caching?
Yes you can! You can use our WP REST Cache Pro plugin to easily register your own endpoints for caching through the wp-admin interface. Or you can do it programmatically by using the hook
wp_rest_cache/allowed_endpointslike this:/** * Register the /wp-json/acf/v3/posts endpoint so it will be cached. */ function wprc_add_acf_posts_endpoint( $allowed_endpoints ) { if ( ! isset( $allowed_endpoints[ 'acf/v3' ] ) || ! in_array( 'posts', $allowed_endpoints[ 'acf/v3' ] ) ) { $allowed_endpoints[ 'acf/v3' ][] = 'posts'; } return $allowed_endpoints; } add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_acf_posts_endpoint', 10, 1);Please note: the WP REST Cache plugin will try to detect relations in the cached data to automatically flush the cache when related items are edited, but this detection is not flawless so your caches might not be flushed automatically.
Can I unregister an endpoint so it is no longer cached?
Yes you can! Use the hook
wp_rest_cache/allowed_endpointslike this:/** * Unregister the /wp-json/wp/v2/comments endpoint so it will not be cached. */ function wprc_unregister_wp_comments_endpoint( $allowed_endpoints ) { if ( isset( $allowed_endpoints[ 'wp/v2' ] ) && ( $key = array_search( 'comments', $allowed_endpoints[ 'wp/v2' ] ) ) !== false ) { unset( $allowed_endpoints[ 'wp/v2' ][ $key ] ); } return $allowed_endpoints; } add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_unregister_wp_comments_endpoint', 100, 1);Can I force a call to the REST API to not use caching?
Yes you can! Add the GET-parameter
skip_cache=1to your call and no caching will be used.On the cache overview page I see the object type is ‘unknown’. Can I help the WP REST Cache plugin to detect the object type correctly?
Yes you can! Use the hook
wp_rest_cache/determine_object_typelike this:function wprc_determine_object_type( $object_type, $cache_key, $data, $uri ) { if ( $object_type !== 'unknown' || strpos( $uri, $your_namespace . '/' . $your_rest_base ) === false ) { return $object_type; } // Do your magic here $object_type = 'website'; // Do your magic here return $object_type; } add_filter( 'wp_rest_cache/determine_object_type', 'wprc_determine_object_type', 10, 4 );Can expired caches be automatically regenerated?
Yes they can! Go to Settings > WP REST Cache, on the Settings tab you can check
Enable cache regeneration, this will activate a cron job which will check if there are any expired (or flushed) caches and regenerate them. Using theRegeneration intervalyou can determine how often this regeneration process should run. TheMax number regenerate cacheslimits the number of regenerated caches per regeneration process, this is so your server doesn’t get flooded with the regeneration calls.Are expired caches removed from the database?
Yes. Once a day a cron job removes caches from the database that expired more than a day ago, or that were flushed and already cleaned up. This only happens when cache regeneration is disabled, because the regeneration needs these caches to know what to regenerate. Use the filter
wp_rest_cache/purge_stale_cachesto override this,wp_rest_cache/stale_cache_grace_periodto change how long (in seconds) an expired cache is kept andwp_rest_cache/max_purge_cachesto change the number of caches removed per run (default 1000).Can I hide the ‘Clear REST cache’ in the wp-admin bar?
Yes you can! Use the hook
wp_rest_cache/display_clear_cache_buttonlike this:function wprc_display_clear_cache_button( $show ) { return false; } add_filter('wp_rest_cache/display_clear_cache_button', 'wprc_display_clear_cache_button', 10, 1);Can I differentiate between caches based upon request headers?
Yes you can! There are two options for this: 1. Go to Settings > WP REST Cache and add
Global cacheable request headers. This is a comma seperated list. These headers will be used for ALL endpoints. 2. Use the hookwp_rest_cache/cacheable_request_headersto specify per endpoint which request headers should be used. Like this:function wprc_add_cacheable_request_headers( $cacheable_headers ) { $cacheable_headers['wp/v2/posts'] = 'LANG'; return $cacheable_headers; } add_filter('wp_rest_cache/cacheable_request_headers', 'wprc_add_cacheable_request_headers', 10, 1);Can I change which users can change the settings and flush caches?
Yes you can! Use the hook
wp_rest_cache/settings_capabilitylike this:function wprc_change_settings_capability( $capability ) { // Change the capability to users who can edit posts. return 'edit_posts'; } add_filter('wp_rest_cache/settings_capability', 'wprc_change_settings_capability', 10, 1);Can I use WP CLI to flush caches from the command line?
Yes you can! Use the
wp wp-rest-cache flushcommand to flush caches. Typewp wp-rest-cache flush --helpto see all options.Is Redis Object Cache supported?
We are using the WordPress transient API, so as long as you are using a Redis Object Cache plugin which enables Redis caching through the transients API it is supported.
How can I report security bugs?
You can report security bugs through the Patchstack Vulnerability Disclosure Program. The Patchstack team helps validate, triage and handle any security vulnerabilities. Report a security vulnerability.
Reviews
Contributors & Developers
“WP REST Cache” is open source software. The following people have contributed to this plugin.
Contributors“WP REST Cache” has been translated into 5 locales. Thank you to the translators for their contributions.
Translate “WP REST Cache” into your language.
Interested in development?
Browse the code, check out the SVN repository, or subscribe to the development log by RSS.
Changelog
2026.4.2
Release Date: October 29th, 2026
Fix: Caches that expired, or that were flushed and cleaned up, were never removed from the database, causing the caches table to grow indefinitely. A daily cron job now removes them (unless cache regeneration is enabled). It was reported by krstarica.
Improvement: The cache regeneration cron no longer loads the entire caches table into memory.
Feature: Added filters wp_rest_cache/purge_stale_caches, wp_rest_cache/stale_cache_grace_period and wp_rest_cache/max_purge_caches.
2026.4.1
Release Date: October 29th, 2026
Fix: Deleted caches that had been flushed and cleaned up before were never removed from the database, causing the caches table to grow indefinitely. Existing leftover caches are removed by the cleanup cron. It was reported by krstarica.
2026.4.0
Release Date: October 27th, 2026
Security: Responses generated for authenticated users (e.g. through Application Passwords or Basic auth) could be cached and served to unauthenticated visitors. Requests with an Authorization header and requests with context=edit are no longer cached, responses for authenticated users are only cached if the cache key is user specific, and nonce cached requests are now cached per session. All existing caches are flushed on update.
Feature: Added filter wp_rest_cache/cache_authenticated_response to allow caching of responses generated for authenticated users when the cache key is made user specific.
2026.3.1
Release Date: July 25th, 2026
Improvement: Make the mu-plugin use the same version as the main plugin.
2026.3.0
Release Date: July 24th, 2026
Fix: several small fixes and improvements.
Improvement: Add support for using regex inside wp_rest_cache/allowed_endpoints and wp_rest_cache/disallowed_endpoints filters.
2026.2.0
Release Date: May 19th, 2026
Fix: specified key was too long error.
Improvement: Extra filters and actions.
2026.1.3
Release Date: March 3rd, 2026
Fix: Prevent performance issue with hierarchical categories.
2026.1.2
Release Date: February 25th, 2026
Fix: Prevent PHP warnings.
Improvement: Add filter to disallow skip_cache parameter.
Improvement: Added error log if set_transient fails.
Improvement: Add support for flushing term cache when objects terms are modified. (Contribution by: Moshe Gross)
2026.1.1
Release Date: January 20th, 2026
Fix: A XSS vulnerability in the plugin was discovered and fixed. It was reported by Nguyen Ba Khanh.
Fix: Improved transition_post_status_logic. (Contribution by: Moshe Gross)
2026.1.0
Release Date: January 14th, 2026
Improvement: Only flush caches on meta update if filter returns true.
2025.2.0
Release Date: December 15th, 2025
Improvement: Also flush caches when only the (post) meta is updated.
Earlier versions
For the changelog of earlier versions, please refer to the changelog on Github.
