-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathreadme.txt
437 lines (294 loc) · 14.9 KB
/
readme.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
=== WP REST Cache ===
Contributors: acato, rockfire, yoeridekker
Tags: cache, wp-rest-api, api, rest, rest cache
Requires at least: 4.7
Tested up to: 6.7
Requires PHP: 7.0
Stable tag: 2024.3.0
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl.html
Enable caching of the WordPress REST API and auto-flush caches upon wp-admin editing.
== 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.
== Installation ==
=== Installation from within WordPress ===
1. Visit 'Plugins > Add New' (or 'My Sites > Network Admin > Plugins > Add New' if you are on a multisite installation).
1. Search for 'WP REST Cache'.
1. Activate the WP REST Cache plugin through the 'Plugins' menu in WordPress.
1. Go to "after activation" below.
=== Installation manually ===
1. Upload the `wp-rest-cache` folder to the `/wp-content/plugins/` directory.
1. Activate the WP REST Cache plugin through the 'Plugins' menu in WordPress.
1. Go to "after activation" below.
=== After activation ===
1. Visit 'Plugins > Must-Use' (or 'My Sites > Network Admin > Plugins > Must-Use' if you are on a multisite installation).
1. Check if the 'WP REST Cache - Must-Use Plugin' is there, if not copy the file `wp-rest-cache.php` from the `/sources` folder 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:
1. Visit 'Settings > WP REST Cache'.
1. Change the Cache timeout.
== Frequently Asked Questions ==
= 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 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! Use the hook `wp_rest_cache/allowed_endpoints` like 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_endpoints` like 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=1` to 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_type` like 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 the `Regeneration interval` you can determine how often this regeneration process should run. The `Max number regenerate caches` limits the number of regenerated caches per regeneration process, this is so your server doesn't get flooded with the regeneration calls.
= Can I hide the 'Clear REST cache' in the wp-admin bar? =
Yes you can! Use the hook `wp_rest_cache/display_clear_cache_button` like this:
`function wprc_hide_clear_cache_button( $show ) {
return true;
}
add_filter('wp_rest_cache/display_clear_cache_button', 'wprc_hide_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 hook `wp_rest_cache/cacheable_request_headers` to 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_capability` like 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 flush` command to flush caches. Type `wp wp-rest-cache flush --help` to see all options.
== Screenshots ==
1. Settings for the WP REST Cache plugin.
2. An overview of cached endpoint calls.
3. An overview of cached single items.
4. Cache details page - Cache info.
5. Cache details page - Cache data.
== Changelog ==
= 2024.3.0 =
Release Date: December 18th, 2024
Feature: Allow defining settings through wp-config constants.
= 2024.2.3 =
Release Date: September 30th, 2024
Bugfix: Fix fatal error when option is false.
= 2024.2.2 =
Release Date: September 9th, 2024
Bugfix: Fix incorrect building of endpoint URL when using WPML.
= 2024.2.1 =
Release Date: August 28th, 2024
Bugfix: Fix error with WP CLI command.
= 2024.2.0 =
Release Date: August 12th, 2024
Improvement: Several small improvements.
= 2024.1.3 =
Release Date: March 20th, 2024
Bugfix: Fix undefined array key warnings.
= 2024.1.2 =
Release Date: March 7th, 2024
Bugfix: Fix where the plugin caused an error on permanently deleting items.
= 2024.1.1 =
Release Date: March 6th, 2024
Bugfix: Several small fixes.
= 2024.1.0 =
Release Date: March 2nd, 2024
Improvement: Upgrade to WPCS 3.
Improvement: Prevent refresh of caches table to redo previous action.
= 2023.2.1 =
Release Date: August 29th, 2023
Bugfix: Make sure notices are shown only once.
= 2023.2.0 =
Release Date: July 21st, 2023
Feature: Added filter to allow filtering of cache headers prior to outputting.
Feature: Added filter to allow filtering whether empty result sets should be cached (Contribution by: @mjulien).
= 2023.1.1 =
Release Date: February 8th, 2023
Hotfix: Fix uncaught TypeError which might occur in rare situations.
= 2023.1.0 =
Release Date: February 6th, 2023
Feature: Added WordPress Oembed endpoint for caching.
Feature: Added action fired when deleting caches.
Feature: Added filter to skip cron deletion of caches and immediately delete the caches.
= 2022.2.2 =
Release Date: October 10th, 2022
Fix: WP CLI command wasn't working correctly anymore.
= 2022.2.1 =
Release Date: August 25th, 2022
Hotfix: Settings page wasn't displayed correctly.
= 2022.2.0 =
Release Date: August 25th, 2022
Feature: Added filter to allow filtering of cache output.
Improvement: Fix conflict with Wordfence.
Improvement: Added notice upon any plugin (de/)activation that cache might need to be cleared.
Improvement: Added phpstan checks and fixed all errors.
= 2022.1.2 =
Release Date: August 12th, 2022
Bugfix: prevent error on clean install.
= 2022.1.1 =
Release Date: July 15th, 2022
Bugfix: prevent notice.
= 2022.1.0 =
Release Date: July 13th, 2022
Bugfix: Fixed regeneration of flushed caches.
Bugfix: Fix possible fatal error on variable not being an array.
Bugfix: Fix deprecation notice for PHP 8.
= 2021.4.1 =
Release Date: September 15th, 2021
Bugfix: Fix notice for missing variable.
= 2021.4.0 =
Release Date: September 15th, 2021
Feature: Added filter for disabling CORS headers.
Feature: Added filter to disallow caching of (sub)endpoints.
Bugfix: Filesystem methods weren't always loaded correctly when the plugin was loaded through a mu-plugin.
= 2021.3.0 =
Release Date: April 15th, 2021
Feature: Added support for when the plugin itself is installed as a mu-plugin.
= 2021.2.1 =
Release Date: February 27th, 2021
Bugfix: Error in delete_object_type_caches function.
= 2021.2.0 =
Release Date: February 24th, 2021
Feature: Added WP CLI command to flush caches from the command line.
Bugfix: Force saved cache to be valid JSON (to prevent errors with invalid JSON responses).
= 2021.1.0 =
Release Date: January 28th, 2021
Feature: Added a filter to allow caching of requests with a nonce.
= 2020.3.2 =
Release Date: November 10th, 2020
Bugfix: Allow CORS headers to be overwritten. (Contribution by @luisherranz)
= 2020.3.1 =
Release Date: October 19th, 2020
Bugfix: Not all caches were flushed correctly after last update.
= 2020.3.0 =
Release Date: October 12th, 2020
Improvement: Cleanup of legacy code.
Feature: Added the option to filter the cache timeout per cache.
= 2020.2.2 =
Release Date: September 7th, 2020
Bugfix: Conflict when caching two calls with same url but different request method.
Bugfix: Bulk actions were broken.
= 2020.2.1 =
Release Date: July 14th, 2020
Bugfix: WordPress bug caused screen options to not work correctly anymore.
= 2020.2.0 =
Release Date: July 2nd, 2020
Improvement: Speed up cache clearing.
Feature: Added filter for programmatically skip caching.
Feature: Added filter to disable cache hit recording.
Feature: Added option to delete all caches (vs flush all caches).
Bugfix: Do not cache API calls with a nonce.
Bugfix: Fix for not caching when there are double slashes in the request path.
Bugfix: Fix persisting the search when searching through caches.
= 2020.1.1 =
Release Date: March 12th, 2020
Bugfix: Allow usage of rest_route parameter.
Bugfix: WordPress database error: specified key was too long.
= 2020.1.0 =
Release Date: January 16th, 2020
Feature: Added a filter to ignore specific query string parameters.
Feature: Make allowed request methods filterable.
Bugfix: Make options not autoload.
= 2019.4.5 =
Release Date: November 22nd, 2019
Bugfix: Do not update database table on each load.
Bugfix: WordPress database error: specified key was too long.
= 2019.4.4 =
Release Date: November 14th, 2019
Hotfix: Fixing WordPress database error.
= 2019.4.3 =
Release Date: November 12th, 2019
Feature: Added filter for Settings page capability.
Bugfix: Problem with non-existing tables after multisite duplication.
= 2019.4.2 =
Release Date: October 15th, 2019
Bugfix: Prevent fatal error after WordPress security update.
= 2019.4.1 =
Release Date: September 5th, 2019
Feature: Flush caches with progressbar and through ajax call to prevent timeout.
Bugfix: Expiration date was displayed incorrectly.
Bugfix: Do not cache empty result set.
Bugfix: Do not use filter_input with INPUT_SERVER, it will break when fastcgi is used (see https://stackoverflow.com/questions/25232975/php-filter-inputinput-server-request-method-returns-null/36205923).
= 2019.4.0 =
Release Date: July 12th, 2019
Feature: Added option to differentiate between caches based upon certain request headers.
Feature: Added option to hide the 'Clear cache' button in the wp-admin bar.
Bugfix: Fix for when WordPress is installed in a subdirectory.
Bugfix: Remove Item Caching, it was causing more problems and complexity than it was improving performance.
= 2019.3.0 =
Release Date: June 18th, 2019
Improvement: Meet WordPress Coding Standards.
Feature: Added expired caches regeneration cron.
Bugfix: Added fallback check for Memcache(d). Memcache(d) treats a transient timeout > 30 days as a timestamp.
= 2019.2.1 =
Release Date: April 15th, 2019
Feature: Added option to skip cache using a parameter.
= 2019.2.0 =
Release Date: April 2nd, 2019
Feature: Added function to programatically flush cache records by endpoint path.
Bugfix: Fix correct filtering of allowed endpoints.
Bugfix: Fix fatal error with object instead of array in cache.
= 2019.1.6 =
Release Date: March 25th, 2019
Feature: Added filters for response header manipulation.
= 2019.1.4 =
Release Date: March 21st, 2019
Bugfix: bug in saving relations for comments endpoint prevented the cache for comments to be flushed automatically.
= 2019.1.3 =
Release Date: February 13th, 2019
Feature: Added support for correctly flushing caches of scheduled posts.
= 2019.1.2 =
Release Date: January 31st, 2019
First public version.