Add redis_calls metric for persistent object cache integration#219
Draft
Add redis_calls metric for persistent object cache integration#219
redis_calls metric for persistent object cache integration#219Conversation
2 tasks
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
… metric Agent-Logs-Url: https://github.com/wp-cli/profile-command/sessions/d00efdc1-7144-4e26-b76c-880aeca9a768 Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
… feedback Agent-Logs-Url: https://github.com/wp-cli/profile-command/sessions/d00efdc1-7144-4e26-b76c-880aeca9a768 Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add integration for persistent object caches
Add Apr 29, 2026
redis_calls metric for persistent object cache integration
tillkruss
suggested changes
Apr 29, 2026
| 'cache_hits' => 0, | ||
| 'cache_misses' => 0, | ||
| 'cache_ratio' => null, | ||
| 'redis_calls' => 0, |
There was a problem hiding this comment.
@copilot instead of redis_calls it might be worth using cache_commands or cache_calls to also support memcached or sqlite later.
| $this->tick_query_offset = ! empty( $wpdb->queries ) ? count( $wpdb->queries ) : 0; | ||
| $this->tick_cache_hit_offset = ! empty( $wp_object_cache->cache_hits ) ? $wp_object_cache->cache_hits : 0; | ||
| $this->tick_cache_miss_offset = ! empty( $wp_object_cache->cache_misses ) ? $wp_object_cache->cache_misses : 0; | ||
| $this->tick_redis_calls_offset = isset( $wp_object_cache->redis_calls ) && is_array( $wp_object_cache->redis_calls ) ? (int) array_sum( $wp_object_cache->redis_calls ) : null; |
There was a problem hiding this comment.
Each plugin has their own property with slightly different names.
WP Redis: $redis_calls
Redis Object Cache: $cache_calls
Object Cache Pro: metrics()->storeReads + metrics()->storeWrites
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Persistent object cache plugins like WP Redis expose
$wp_object_cache->redis_calls(an associative array of Redis command → count), butwp profilehad no way to surface this data.Changes
src/Logger.php— adds$redis_callspublic property;start()capturesarray_sum($wp_object_cache->redis_calls)as an offset,stop()computes and stores the delta. Gracefully no-ops whenredis_callsis absent (default WP object cache).src/Profiler.php— adds$tick_redis_calls_offsetfor tick-based (function-level) profiling; mirrors the same offset/delta pattern inhandle_function_tick().src/Command.php— addsredis_callsto the$metricsfields forstage,hook,eval, andeval-filesubcommands.features/profile-eval.feature— two new scenarios: one assertingredis_calls = 0with the default cache; one using a minimalobject-cache.phpdrop-in that mimics WP Redis'sredis_callstracking to assert the count is correct.Example output
Any persistent object cache that stores call counts in
$wp_object_cache->redis_calls(WP Redis and compatible plugins) will automatically benefit from this integration.