Skip to content

Improve object cache detection#17

Merged
desrosj merged 6 commits intotrunkfrom
improve/object-cache-detection
May 5, 2026
Merged

Improve object cache detection#17
desrosj merged 6 commits intotrunkfrom
improve/object-cache-detection

Conversation

@desrosj
Copy link
Copy Markdown
Member

@desrosj desrosj commented May 1, 2026

This makes a number of improvements to object cache detection to prevent false positives and inaccurate outcomes:

  • The `WP_REDIS_VERSION constant is set by a plugin file, not the actual drop-in, so it produces inaccurate results when the drop-in is present but the plugin is deactivated.
  • Bare class_exists('Memcached') / class_exists('Memcache') checks can cause false positives because they only test whether the PHP extension is loaded, not whether it's actually the active cache backend.
  • WP_CACHE_KEY_SALT is not just a Memcached signal. It's used by multiple drop-ins (including Redis), so should not be used as a reliable indicator.
  • Redis detection now uses method_exists($wp_object_cache, 'redis_status'). Because this method lives in the drop-in class, it will work regardless of whether the plugin is active.
  • Memcached detection now inspects the $mc property on the cache object and checks whether it's an actual Memcached or Memcache instance. Prevents false positives when the extension is available but the drop-in is not.
  • WP Redis detection still uses WP_REDIS_OBJECT_CACHE but now also falls back to a $redis property check.
  • The redis-disconnected return value distinguishes "Redis drop-in installed and connected" from "Redis drop-in installed but silently falling back to in-memory because the server is unreachable."
  • Added Object Cache Pro detection.
  • Added LiteSpeed Cache detection.
  • Added W3 Total Cache detection.
  • Added APCu drop-in detection.
  • 'ext:unknown' is returned early when $wp_object_cache is not a valid object.

desrosj added 2 commits May 1, 2026 15:33
To help hosts understand what data was submitted, the values will now be saved into a log file.
This makes a number of improvements to object cache detection:

- The `WP_REDIS_VERSION constant is set by a plugin file, not the actual drop-in, so it produces inaccurate results when the drop-in is present but the plugin is deactivated.
- Bare `class_exists('Memcached')` / `class_exists('Memcache')` checks can cause false positives because they only test whether the PHP extension is loaded, not whether it's actually the active cache backend.
- `WP_CACHE_KEY_SALT` is not just a Memcached signal. It's used by multiple drop-ins (including Redis), so should not be used as a reliable indicator.
- Redis detection now uses `method_exists($wp_object_cache, 'redis_status')`. Because this method lives in the drop-in class, it will work regardless of whether the plugin is active.
- Memcached detection now inspects the `$mc` property on the cache object and checks whether it's an actual Memcached or Memcache instance. Prevents false positives when the extension is available but the drop-in is not.
- WP Redis detection still uses `WP_REDIS_OBJECT_CACHE` but now also falls back to a `$redis` property check.
- The `redis-disconnected` return value distinguishes "Redis drop-in installed and connected" from "Redis drop-in installed but silently falling back to in-memory because the server is unreachable."
- Added Object Cache Pro detection.
- Added LiteSpeed Cache detection.
- Added W3 Total Cache detection.
- Added APCu drop-in detection.
- 'ext:unknown' is returned early when $wp_object_cache is not a valid object.
@desrosj desrosj self-assigned this May 1, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refines the environment-reporting logic in rtc-test.php so object_cache_type is inferred from the active drop-in object rather than from loose constants/extension checks, reducing false positives in cache backend reporting.

Changes:

  • Reworked object cache detection to inspect the active $wp_object_cache instance first and return ext:unknown early when it is unavailable.
  • Replaced broad Redis/Memcache heuristics with drop-in-specific checks such as redis_status(), $redis, and $mc.
  • Added explicit detection branches for Object Cache Pro, LiteSpeed Cache, W3 Total Cache, APCu, and a redis-disconnected state.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rtc-test.php Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread rtc-test.php Outdated
Co-authored-by: Dion Hulse <dd32@dd32.id.au>
@desrosj desrosj merged commit 8bf75c3 into trunk May 5, 2026
@desrosj desrosj deleted the improve/object-cache-detection branch May 5, 2026 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants