run:R W Run
DIR
2026-04-09 18:51:36
R W Run
DIR
2026-04-09 18:51:36
R W Run
DIR
2026-04-09 18:51:36
R W Run
42.31 KB
2026-04-09 18:51:36
R W Run
14.57 KB
2026-04-09 18:51:36
R W Run
1.09 KB
2026-04-09 18:51:36
R W Run
19.59 KB
2026-04-09 18:51:36
R W Run
3.33 KB
2026-04-09 18:51:36
R W Run
2.5 KB
2026-04-09 18:51:36
R W Run
2.42 KB
2026-04-09 18:51:36
R W Run
324 By
2026-04-09 18:51:36
R W Run
2.55 KB
2026-04-09 18:51:36
R W Run
error_log
📄api.php
1<?php
2/**
3 * Copyright © 2019-2026 Rhubarb Tech Inc. All Rights Reserved.
4 *
5 * The Object Cache Pro Software and its related materials are property and confidential
6 * information of Rhubarb Tech Inc. Any reproduction, use, distribution, or exploitation
7 * of the Object Cache Pro Software and its related materials, in whole or in part,
8 * is strictly forbidden unless prior permission is obtained from Rhubarb Tech Inc.
9 *
10 * In addition, any reproduction, use, distribution, or exploitation of the Object Cache Pro
11 * Software and its related materials, in whole or in part, is subject to the End-User License
12 * Agreement accessible in the included `LICENSE` file, or at: https://objectcache.pro/eula
13 */
14
15declare(strict_types=0);
16
17defined('ABSPATH') || exit;
18
19require_once __DIR__ . '/bootstrap.php';
20
21/**
22 * Determines whether the object cache implementation supports a particular feature.
23 *
24 * Possible values include:
25 * - `add_multiple`, `set_multiple`, `get_multiple` and `delete_multiple`
26 * - `flush_runtime` and `flush_group`
27 *
28 * @param string $feature Name of the feature to check for.
29 * @return bool True if the feature is supported, false otherwise.
30 */
31function wp_cache_supports($feature)
32{
33 switch ($feature) {
34 case 'add_multiple':
35 case 'set_multiple':
36 case 'get_multiple':
37 case 'delete_multiple':
38 case 'flush_runtime':
39 case 'flush_group':
40 return true;
41
42 default:
43 return false;
44 }
45}
46
47/**
48 * Set up the global `$wp_object_cache`.
49 *
50 * @global array $wp_object_cache_errors
51 * @global \RedisCachePro\ObjectCaches\ObjectCacheInterface $wp_object_cache
52 * @return void
53 */
54function wp_cache_init()
55{
56 global $wp_object_cache, $wp_object_cache_errors, $wp_object_cache_flushlog;
57
58 if ($wp_object_cache instanceof \RedisCachePro\ObjectCaches\ObjectCacheInterface) {
59 return;
60 }
61
62 $wp_object_cache_errors = [];
63 $wp_object_cache_flushlog = [];
64
65 try {
66 if (! defined('WP_REDIS_CONFIG')) {
67 throw new \RedisCachePro\Exceptions\ConfigurationMissingException;
68 }
69
70 $config = \WP_REDIS_CONFIG;
71
72 // set `debug` config value to `WP_DEBUG`, if not present already
73 if (! isset($config['debug']) && defined('WP_DEBUG')) {
74 $config['debug'] = (bool) \WP_DEBUG;
75 }
76
77 // set `save_commands` config value to `SAVEQUERIES`, if not present already
78 if (! isset($config['save_commands']) && defined('SAVEQUERIES')) {
79 $config['save_commands'] = (bool) \SAVEQUERIES;
80 }
81
82 $config = \RedisCachePro\Configuration\Configuration::from($config)->validate();
83 $connection = $config->connector::connect($config);
84
85 /** @var \RedisCachePro\ObjectCaches\ObjectCacheInterface $objectCache */
86 $objectCache = new $config->cache($connection, $config);
87
88 // register additional global groups
89 if ($config->global_groups) {
90 $objectCache->add_global_groups($config->global_groups);
91 }
92
93 // register additional non-persistent groups
94 if ($config->non_persistent_groups) {
95 $objectCache->add_non_persistent_groups($config->non_persistent_groups);
96 }
97
98 // register non-prefetchable groups
99 if ($config->non_prefetchable_groups) {
100 $objectCache->add_non_prefetchable_groups($config->non_prefetchable_groups);
101 }
102
103 $objectCache->add_global_groups([
104 'analytics',
105 'objectcache',
106 ]);
107
108 $objectCache->add_non_prefetchable_groups([
109 'analytics',
110 'objectcache',
111 'userlogins',
112 'wc_cache_*',
113 defined('WC_SESSION_CACHE_GROUP') ? WC_SESSION_CACHE_GROUP : 'wc_session_id',
114 ]);
115
116 // set up multisite environments
117 if (is_multisite()) {
118 $objectCache->setMultisite(true);
119
120 // prefetch once `$blog_id` is available
121 if (method_exists($objectCache, 'prefetch')) {
122 add_action('ms_loaded', [$objectCache, 'prefetch'], 0);
123 }
124 }
125
126 $objectCache->boot();
127
128 $wp_object_cache = $objectCache;
129 } catch (Throwable $exception) {
130 $error = sprintf('Failed to initialize object cache: %s', $exception->getMessage());
131
132 $wp_object_cache_errors[] = $error;
133
134 error_log("objectcache.critical: {$error}");
135
136 if (! isset($config) || ! ($config instanceof \RedisCachePro\Configuration\Configuration)) {
137 $config = (new \RedisCachePro\Configuration\Configuration)->init();
138 }
139
140 if ($config->debug || $config->strict) {
141 \RedisCachePro\Exceptions\ExceptionHandler::render($config, $exception);
142 }
143
144 error_log('objectcache.warning: Failing over to in-memory object cache');
145
146 $wp_object_cache = new \RedisCachePro\ObjectCaches\ArrayObjectCache($config);
147 }
148
149 \register_shutdown_function([$wp_object_cache, 'close']);
150}
151
152/**
153 * Adds data to the cache, if the cache key doesn't already exist.
154 *
155 * @param int|string $key The cache key to use for retrieval later.
156 * @param mixed $data The data to add to the cache.
157 * @param string $group Optional. The group to add the cache to. Enables the same key
158 * to be used across groups. Default empty.
159 * @param int $expire Optional. When the cache data should expire, in seconds.
160 * Default 0 (no expiration).
161 * @return bool True on success, false if cache key and group already exist.
162 */
163function wp_cache_add($key, $data, $group = '', $expire = 0)
164{
165 global $wp_object_cache;
166
167 return $wp_object_cache->add($key, $data, \trim((string) $group) ?: 'default', (int) $expire);
168}
169
170/**
171 * Adds multiple values to the cache in one call.
172 *
173 * @param array<mixed> $data Array of keys and values to be set.
174 * @param string $group Optional. Where the cache contents are grouped. Default empty.
175 * @param int $expire Optional. When to expire the cache contents, in seconds.
176 * Default 0 (no expiration).
177 * @return bool[] Array of return values, grouped by key. Each value is either
178 * true on success, or false if cache key and group already exist.
179 */
180function wp_cache_add_multiple(array $data, $group = '', $expire = 0)
181{
182 global $wp_object_cache;
183
184 return $wp_object_cache->add_multiple($data, \trim((string) $group) ?: 'default', (int) $expire);
185}
186
187/**
188 * Closes the cache.
189 *
190 * To increase Query Monitor compatibility this method does nothing.
191 * Instead the `wp_cache_init` method registers a shutdown
192 * function that calls `$wp_object_cache->close()`.
193 *
194 * @see wp_cache_init()
195 *
196 * @return true Always returns true.
197 */
198function wp_cache_close()
199{
200 return true;
201}
202
203/**
204 * Decrements numeric cache item's value.
205 *
206 * To preserve the key's expiry Redis 6.0 and PhpRedis 5.3 or newer is required.
207 *
208 * @param int|string $key The cache key to decrement.
209 * @param int $offset Optional. The amount by which to decrement the item's value.
210 * Default 1.
211 * @param string $group Optional. The group the key is in. Default empty.
212 * @return int|false The item's new value on success, false on failure.
213 */
214function wp_cache_decr($key, $offset = 1, $group = '')
215{
216 global $wp_object_cache;
217
218 return $wp_object_cache->decr($key, (int) $offset, \trim((string) $group) ?: 'default');
219}
220
221/**
222 * Removes the cache contents matching key and group.
223 *
224 * @param int|string $key What the contents in the cache are called.
225 * @param string $group Optional. Where the cache contents are grouped. Default empty.
226 * @return bool True on successful removal, false on failure.
227 */
228function wp_cache_delete($key, $group = '')
229{
230 global $wp_object_cache;
231
232 return $wp_object_cache->delete($key, \trim((string) $group) ?: 'default');
233}
234
235/**
236 * Deletes multiple values from the cache in one call.
237 *
238 * @param array<string> $keys Array of keys under which the cache to delete.
239 * @param string $group Optional. Where the cache contents are grouped. Default empty.
240 * @return bool[] Array of return values, grouped by key. Each value is either
241 * true on success, or false if the contents were not deleted.
242 */
243function wp_cache_delete_multiple(array $keys, $group = '')
244{
245 global $wp_object_cache;
246
247 return $wp_object_cache->delete_multiple($keys, \trim((string) $group) ?: 'default');
248}
249
250/**
251 * Removes all cache items.
252 *
253 * @return bool True on success, false on failure.
254 */
255function wp_cache_flush()
256{
257 global $wp_object_cache, $wp_object_cache_flushlog, $blog_id;
258
259 $backtrace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 5);
260
261 if (\function_exists('\apply_filters')) {
262 /**
263 * Whether to flush the object cache.
264 *
265 * Returning a falsy value from the filter will short-circuit the flush.
266 *
267 * @param bool $should_flush Whether to flush the object cache.
268 * @param array $backtrace The PHP backtrace with 5 stack frames.
269 */
270 $should_flush = (bool) \apply_filters('pre_objectcache_flush', true, $backtrace);
271
272 if (! $should_flush) {
273 return false;
274 }
275 }
276
277 if ($wp_object_cache->shouldFlushBlog()) {
278 if (defined('WP_CLI') && WP_CLI) {
279 $wp_object_cache->switch_to_blog((int) $blog_id);
280 }
281
282 return $wp_object_cache->flushBlog();
283 }
284
285 $wp_object_cache_flushlog[] = [
286 'type' => 'flush',
287 'backtrace' => $backtrace,
288 ];
289
290 return $wp_object_cache->flush();
291}
292
293/**
294 * Removes all cache items from the in-memory runtime cache.
295 *
296 * @return bool True on success, false on failure.
297 */
298function wp_cache_flush_runtime()
299{
300 global $wp_object_cache;
301
302 return $wp_object_cache->flush_runtime();
303}
304
305/**
306 * Removes all cache items in a group.
307 *
308 * @param string $group Name of group to remove from cache.
309 * @return bool True if group was flushed, false otherwise.
310 */
311function wp_cache_flush_group($group = '')
312{
313 global $wp_object_cache, $wp_object_cache_flushlog;
314
315 $group = \trim((string) $group) ?: 'default';
316 $backtrace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 5);
317
318 if (\function_exists('\apply_filters')) {
319 /**
320 * Whether to flush the cache group.
321 *
322 * Returning a falsy value from the filter will short-circuit the group flush.
323 *
324 * @param bool $should_flush Whether to flush the cache group.
325 * @param string $group The name of the cache group.
326 * @param array $backtrace The PHP backtrace with 5 stack frames.
327 */
328 $should_flush = (bool) \apply_filters('pre_objectcache_flush_group', true, $group, $backtrace);
329
330 if (! $should_flush) {
331 return false;
332 }
333 }
334
335 $wp_object_cache_flushlog[] = [
336 'type' => 'group-flush',
337 'group' => $group,
338 'backtrace' => $backtrace,
339 ];
340
341 return $wp_object_cache->flush_group($group);
342}
343
344/**
345 * Determines whether the object cache implementation supports flushing individual cache groups.
346 *
347 * @return bool True if group flushing is supported, false otherwise.
348 */
349function wp_cache_supports_group_flush()
350{
351 return true;
352}
353
354/**
355 * Retrieves the cache contents from the cache by key and group.
356 *
357 * Using `$found` to disambiguate a return value of `false` requires
358 * PhpRedis 6.2.0 or Relay v0.10.1 or newer.
359 *
360 * @param int|string $key The key under which the cache contents are stored.
361 * @param string $group Optional. Where the cache contents are grouped. Default empty.
362 * @param bool $force Optional. Whether to force an update of the local cache
363 * from the persistent cache. Default false.
364 * @param bool $found Optional. Whether the key was found in the cache (passed by reference).
365 * Disambiguates a return of false, a storable value. Default null.
366 * @return mixed|false The cache contents on success, false on failure to retrieve contents.
367 */
368function wp_cache_get($key, $group = '', $force = false, &$found = null)
369{
370 global $wp_object_cache;
371
372 return $wp_object_cache->get($key, \trim((string) $group) ?: 'default', (bool) $force, $found);
373}
374
375/**
376 * Retrieves multiple values from the cache in one call.
377 *
378 * @param array<string> $keys Array of keys under which the cache contents are stored.
379 * @param string $group Optional. Where the cache contents are grouped. Default empty.
380 * @param bool $force Optional. Whether to force an update of the local cache
381 * from the persistent cache. Default false.
382 * @return array<mixed> Array of return values, grouped by key. Each value is either
383 * the cache contents on success, or false on failure.
384 */
385function wp_cache_get_multiple($keys, $group = '', $force = false)
386{
387 global $wp_object_cache;
388
389 return $wp_object_cache->get_multiple((array) $keys, \trim((string) $group) ?: 'default', (bool) $force);
390}
391
392/**
393 * Increments numeric cache item's value.
394 *
395 * To preserve the key's expiry Redis 6.0 and PhpRedis 5.3 or newer is required.
396 *
397 * @param int|string $key The key for the cache contents that should be incremented.
398 * @param int $offset Optional. The amount by which to increment the item's value.
399 * Default 1.
400 * @param string $group Optional. The group the key is in. Default empty.
401 * @return int|false The item's new value on success, false on failure.
402 */
403function wp_cache_incr($key, $offset = 1, $group = '')
404{
405 global $wp_object_cache;
406
407 return $wp_object_cache->incr($key, (int) $offset, \trim((string) $group) ?: 'default');
408}
409
410/**
411 * Replaces the contents of the cache with new data.
412 *
413 * @param int|string $key The key for the cache data that should be replaced.
414 * @param mixed $data The new data to store in the cache.
415 * @param string $group Optional. The group for the cache data that should be replaced.
416 * Default empty.
417 * @param int $expire Optional. When to expire the cache contents, in seconds.
418 * Default 0 (no expiration).
419 * @return bool True if contents were replaced, false if original value does not exist.
420 */
421function wp_cache_replace($key, $data, $group = '', $expire = 0)
422{
423 global $wp_object_cache;
424
425 return $wp_object_cache->replace($key, $data, \trim((string) $group) ?: 'default', (int) $expire);
426}
427
428/**
429 * Saves the data to the cache.
430 *
431 * Differs from wp_cache_add() and wp_cache_replace() in that it will always write data.
432 *
433 * @param int|string $key The cache key to use for retrieval later.
434 * @param mixed $data The contents to store in the cache.
435 * @param string $group Optional. Where to group the cache contents. Enables the same key
436 * to be used across groups. Default empty.
437 * @param int $expire Optional. When to expire the cache contents, in seconds.
438 * Default 0 (no expiration).
439 * @return bool True on success, false on failure.
440 */
441function wp_cache_set($key, $data, $group = '', $expire = 0)
442{
443 global $wp_object_cache;
444
445 return $wp_object_cache->set($key, $data, \trim((string) $group) ?: 'default', (int) $expire);
446}
447
448/**
449 * Sets multiple values to the cache in one call.
450 *
451 * @param array<mixed> $data Array of keys and values to be set.
452 * @param string $group Optional. Where the cache contents are grouped. Default empty.
453 * @param int $expire Optional. When to expire the cache contents, in seconds.
454 * Default 0 (no expiration).
455 * @return bool[] Array of return values, grouped by key. Each value is either
456 * true on success, or false on failure.
457 */
458function wp_cache_set_multiple(array $data, $group = '', $expire = 0)
459{
460 global $wp_object_cache;
461
462 return $wp_object_cache->set_multiple($data, \trim((string) $group) ?: 'default', (int) $expire);
463}
464
465/**
466 * Switches the internal blog ID.
467 *
468 * This changes the blog id used to create keys in blog specific groups.
469 *
470 * @param int $blog_id Site ID.
471 * @return void
472 */
473function wp_cache_switch_to_blog($blog_id)
474{
475 global $wp_object_cache;
476
477 $wp_object_cache->switch_to_blog((int) $blog_id);
478}
479
480/**
481 * Adds a group or set of groups to the list of global groups.
482 *
483 * @param string|string[] $groups A group or an array of groups to add.
484 * @return void
485 */
486function wp_cache_add_global_groups($groups)
487{
488 global $wp_object_cache;
489
490 $wp_object_cache->add_global_groups((array) $groups);
491}
492
493/**
494 * Adds a group or set of groups to the list of non-persistent groups.
495 *
496 * @param string|string[] $groups A group or an array of groups to add.
497 * @return void
498 */
499function wp_cache_add_non_persistent_groups($groups)
500{
501 global $wp_object_cache;
502
503 $wp_object_cache->add_non_persistent_groups((array) $groups);
504}
505
506/**
507 * Resets internal cache keys and structures.
508 *
509 * If the cache back end uses global blog or site IDs as part of its cache keys,
510 * this function instructs the back end to reset those keys and perform any cleanup
511 * since blog or site IDs have changed since cache init.
512 *
513 * This function is deprecated. Use wp_cache_switch_to_blog() instead of this
514 * function when preparing the cache for a blog switch. For clearing the cache
515 * during unit tests, consider using wp_cache_init(). wp_cache_init() is not
516 * recommended outside of unit tests as the performance penalty for using it is high.
517 *
518 * @deprecated Use wp_cache_switch_to_blog()
519 * @return void
520 */
521function wp_cache_reset()
522{
523 _deprecated_function(__FUNCTION__, '3.5.0', 'WP_Object_Cache::reset()');
524}
525
526/**
527 * Adds a group or set of groups to the list of non-prefetchable groups.
528 *
529 * This is a non-standard function that does not ship with WordPress,
530 * be sure to copy it when uninstalling Object Cache Pro.
531 *
532 * @param string|array<string> $groups A group or an array of groups to add.
533 * @return void
534 */
535function wp_cache_add_non_prefetchable_groups($groups)
536{
537 global $wp_object_cache;
538
539 $wp_object_cache->add_non_prefetchable_groups((array) $groups);
540}
541
542/**
543 * Get data from the cache, or execute the given Closure and store the result.
544 *
545 * This is a non-standard function that does not ship with WordPress,
546 * be sure to copy it when uninstalling Object Cache Pro.
547 *
548 * @param int|string $key The key under which the cache contents are stored.
549 * @param int $expire Optional. When the cache data should expire, in seconds.
550 * Default 0 (no expiration).
551 * @param Closure $callback The contents to store in the cache.
552 * @param string $group Optional. Where the cache contents are grouped. Default empty.
553 * @return bool|mixed False on failure to retrieve contents or the cache
554 * contents on success
555 */
556function wp_cache_remember($key, $expire, Closure $callback, $group = '')
557{
558 $data = wp_cache_get($key, $group);
559
560 if ($data !== false) {
561 return $data;
562 }
563
564 $data = $callback();
565
566 wp_cache_set($key, $data, $group, $expire);
567
568 return $data;
569}
570
571/**
572 * Get data from the cache, or execute the given Closure and store the result forever.
573 *
574 * This is a non-standard function that does not ship with WordPress,
575 * be sure to copy it when uninstalling Object Cache Pro.
576 *
577 * @param int|string $key The key under which the cache contents are stored.
578 * @param Closure $callback The contents to store in the cache.
579 * @param string $group Optional. Where the cache contents are grouped. Default empty.
580 * @return bool|mixed False on failure to retrieve contents or the cache
581 * contents on success
582 */
583function wp_cache_sear($key, Closure $callback, $group = '')
584{
585 return wp_cache_remember($key, 0, $callback, $group);
586}
587