Skip to content

Issue/26 cache layer metrics#27

Merged
blackopsrepl merged 3 commits intomainfrom
issue/26-cache-layer-metrics
Mar 27, 2026
Merged

Issue/26 cache layer metrics#27
blackopsrepl merged 3 commits intomainfrom
issue/26-cache-layer-metrics

Conversation

@blackopsrepl
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 686b7359cd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +69 to +73
pub load_requests: u64,
pub memory_hits: u64,
pub disk_hits: u64,
pub network_fetches: u64,
pub in_flight_waits: u64,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve CacheStats compatibility in 2.x releases

This commit removes the public CacheStats surface (hits, misses, and hit_ratio) and replaces it with new fields, which is a source-compatible break for existing 2.x consumers that currently compile against those members. Any downstream code reading stats.hits or calling stats.hit_ratio() will fail to build after updating. To avoid breaking users, keep deprecated compatibility accessors/fields for the 2.x line (or publish this as a major-version API break).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This API change is intentional. The old hits / misses / hit_ratio() surface was materially misleading, so we do not want to preserve it in the new metrics model. We are treating this as an acceptable breaking change for this release line rather than carrying forward compatibility accessors that keep the ambiguous semantics alive.

Comment on lines 434 to 437
async fn get_cached_network(cache_key: String) -> Option<NetworkRef> {
let cache_guard = cache().read().await;
if cache_guard.contains_key(&cache_key) {
record_hit();
Some(NetworkRef::new(cache_guard, cache_key))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Record memory hits for cache returns in load_or_insert

get_cached_network no longer increments any memory-hit metric, but load_or_insert uses this helper after the initial fast-path check. Under concurrent requests, a call can miss at load_or_fetch's first check, then return from memory here after another task inserts the network, and that successful memory-served request is never counted in memory_hits. This makes the new cache-outcome metrics systematically under-report memory hits during contention/races.

Useful? React with 👍 / 👎.

@blackopsrepl blackopsrepl merged commit 2bfde95 into main Mar 27, 2026
7 checks passed
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.

1 participant