
Rockfire – REST API Cache
v1.0.0Richard Korthuis · 2026年11月25日 上架
Fast, security-hardened caching for the WordPress REST API, with tag-based invalidation, a route manager and WP-CLI commands.
- 正在使用
- 10 以下
- 评分
- 暂无
- 累计下载
- 0
- 最近更新
- 2026年11月25日
贡献者
截图





Rockfire – REST API Cache stores the JSON responses of the WordPress REST API and serves repeated anonymous GET requests from the cache, before most of WordPress has loaded. Cached responses are flushed when the content they contain changes, so headless front ends, apps and decoupled sites get fast responses without stale data.
Features
- Early serving. A small must-use file serves cache hits before regular plugins and the theme load. Without it the plugin still works in fallback mode and serves hits from
plugins_loaded. - Route manager. Every readable
wp/v2route and the oEmbed route are cached by default. Under REST API Cache Routes you enable or exclude any registered route (or a wildcard family of routes) and set its TTL, accepted parameters, ignored and bypass parameters, vary headers, and the post types and taxonomies whose changes flush it. Routes that only havePOST,PUTorPATCHhandlers are listed too, and a route can opt in to caching thePOST,PUTorPATCHmethods it registers (never onwp/v2). - Tag-based invalidation. Every cached response is tagged with the posts, terms, users, comments and lists it contains. Saving, trashing or deleting content, and changing terms, REST-exposed meta, users, comments or relevant options flushes the responses carrying those tags. A post response only refers to its terms, so adding another post to one of its categories or removing one from it, and renaming or describing a category, flush the category’s own responses but not the other posts in it. A post response is flushed when its own terms change, or when one of its terms is deleted or gets a new slug or parent.
- Public PHP API. Flush by tag, URL, route or everything, and add your own tags to responses:
rfrac_flush_tag(),rfrac_flush_url(),rfrac_flush_route(),rfrac_flush_all()andrfrac_tag_response(). - Pruning and limits. An hourly maintenance run deletes flushed and expired entries and evicts the least recently used entries above the entry limit. The payload size, the number of query parameters, the query length and the number of tags per entry are limited.
- Object-cache store. With a persistent object cache the payloads are served from the object cache, so the plugin looks up and serves a hit without querying its database tables.
- WP-CLI.
wp rfrac flush,wp rfrac list,wp rfrac status,wp rfrac pruneandwp rfrac config get. - Multisite. Per-site tables and settings, network activation, automatic setup of new sites and
--networkoptions in WP-CLI. - WooCommerce. With WooCommerce active, the public Store API catalog (products, categories, brands, tags, attributes and reviews) can be cached once you enable it under REST API Cache Routes. The cart, checkout, orders and every logged-in shopper are never cached.
- Admin screens and Site Health. Browse and flush cached responses, manage routes and settings, check the must-use file and run maintenance from the REST API Cache menu; Site Health reports problems.
What is never cached
Requests from logged-in users; requests with an Authorization header, a nonce (the X-WP-Nonce header or a _wpnonce parameter, unless the rfrac/nonce_caching filter lets a logged-out request that only carries a nonce be cached), an API key header or a login, session or post password cookie (a login cookie is never cached, whatever the filters say); requests with a method the route is not opted in to (only GET, unless the route opts in to POST, PUT or PATCH); requests with an X-HTTP-Method-Override header; GET requests that carry a body; requests with a multipart, invalid or oversized body, or a body that is neither JSON nor a URL-encoded form; a context other than view or embed; status queries other than publish; requests with a response format parameter (_jsonp, _envelope, _pretty or _method); the routes on the hard deny-list (/wp/v2/users/me, /batch/v1, the WooCommerce Store API cart, checkout, order, batch and shopper-list routes, and the WooCommerce wc/agentic and wc/private routes); requests over the limits (a route longer than 191 bytes, a query string longer than 2048 bytes, more query parameters than the configured maximum, or a route or parameter that is not valid UTF-8; the route is checked as sent, so a percent-encoded byte such as %FF in the path is plain ASCII); and responses that are not 200 OK, are empty result sets, are larger than the payload limit, carry more tags than the tag limit, set a cookie, are marked private, no-store, no-cache or max-age=0, or are vetoed by the rfrac/store_allowed filter. No new responses are stored while the cache holds about 1.5 times the entry limit, until maintenance has pruned it.
Credits
Rockfire – REST API Cache is a fork of WP REST Cache by Acato (https://wordpress.org/plugins/wp-rest-cache/), GPLv3.
Significant changes from WP REST Cache
- Security fixes: responses are never cached for authenticated requests (logged-in users,
Authorization, nonces unless therfrac/nonce_cachingfilter lets a logged-out request that only carries a nonce be cached, credential headers and cookies; a login cookie always bypasses); routes are matched strictly against the registered routes; the cache key is built from the parameters a route knows, and unknown parameters bypass the cache instead of creating new entries; sizes and counts are limited; the plugin makes no outbound HTTP requests and stores no credentials; only an allow-list of response headers is replayed. - A new architecture and database schema (
rfrac_entriesandrfrac_tags), a compiled configuration that the early phase reads without loading other plugins, and a database or object-cache store. - A route manager instead of a list of allowed endpoints.
- Tag-based invalidation instead of object-type relations, with a public PHP API.
- Pruning and size limits keep the cache tables bounded.
- The
wp rfracWP-CLI commands. - Full multisite support.
- A real uninstall that removes every table, option, transient, user meta key, cron event and the must-use file.
- The cache regeneration cron and the upsell have been removed.
Must-use file
What: the plugin installs wp-content/mu-plugins/rfrac-early-cache.php (in the must-use plugins directory, WPMU_PLUGIN_DIR). It is a small loader that does nothing unless this plugin is active.
Why: must-use plugins load before regular plugins, so a cache hit is served before other plugins and the theme are loaded. That is what makes a hit fast.
When it is written: at exactly three moments. On activation (on multisite only when the activating user may manage network plugins, manage_network_plugins; an activation by a site administrator or from WP-CLI does not write it). When someone clicks the “Install must-use file” button (a user who may manage plugins, activate_plugins; on multisite manage_network_plugins, because the file is shared by the whole network). And when this plugin is updated, by any updater (including automatic updates), while an outdated copy built from the plugin’s template (it carries an RFRAC Template: header) already exists: that copy is refreshed. An update never creates a missing file and never touches a file that is not built from the template. Nothing else writes the file. It is written atomically: a temporary file is written, verified and renamed into place, and the plugin never asks for FTP credentials.
Notice: when the file is missing or outdated, a notice with an “Install must-use file” button appears on the Plugins screen and on the plugin’s own pages for a user who may install it, and the plugin serves cache hits from plugins_loaded (fallback mode) until it is installed.
When it is removed: on deactivation, unless the plugin is still active on another site of the network, and on uninstall.
Fallback mode: when the file cannot be written (the directory is not writable, WordPress cannot write files directly, or DISALLOW_FILE_MODS is set) the plugin keeps working and serves cache hits from plugins_loaded. REST API Cache Tools and Site Health show the mode and the reason.
Manual install: copy wp-content/plugins/rockfire-rest-api-cache/mu-plugin/rfrac-early-cache.php to wp-content/mu-plugins/rfrac-early-cache.php, then in the copy replace {{RFRAC_PLUGIN_VERSION}} with the plugin version and {{RFRAC_PLUGIN_BASENAME}} with rockfire-rest-api-cache/rockfire-rest-api-cache.php. REST API Cache Tools shows the exact values for your site.
Opting out: add define( 'RFRAC_DISABLE_MU_INSTALL', true ); to wp-config.php and the plugin never writes the file.
Privacy
The plugin does not track users, does not send data to external services and makes no external HTTP requests. It only caches public REST API responses: requests carrying credentials are never cached. All cached data is stored in your own database (or object cache) and is removed when the plugin is uninstalled.