AgentSkillsCN

cache-observability

跟踪缓存命中率、延迟并检测缓存相关问题

SKILL.md
--- frontmatter
name: cache-observability
description: "Track cache hit rates, latency, and detect cache-related issues"
triggers:
  - "cache metrics"
  - "Redis monitoring"
  - "cache hit rate"
  - "cache performance"
priority: 2

Cache Observability

Cache is performance-critical. Track hit rate, latency, and evictions.

Key Metrics

MetricTypeDescription
cache.hitsCounterSuccessful reads
cache.missesCounterReads that missed
cache.gets.durationHistogramGET latency
cache.evictionsCounterKeys evicted
cache.memory.usedGaugeMemory consumption

Span Attributes

AttributeExampleRequired
cache.systemredis, memcachedYes
cache.operationGET, SETYes
cache.hittrue/falseYes
cache.key_prefixuser:*Recommended (not full key!)

Hit Rate

code
hit_rate = cache.hits / (cache.hits + cache.misses)
  • Good: >90%
  • Concerning: <80% → Check TTL, warming strategy

Issues to Detect

IssueDetectionFix
Low hit rate<80%Tune TTL, warm cache
Cache stampedeMany misses for same keyDistributed locks
High latencyp99 >10msCheck network, value size
Memory pressurememory >90% of maxEviction policy, sizing

Cache Wrapper Pattern

code
Before GET: Start timer
After GET:  Record duration, increment hits or misses, set cache.hit on span

Anti-Patterns

  • Full keys in metrics → High cardinality, use prefix only
  • No eviction monitoring → Can't detect memory pressure
  • Ignoring serialization time → Track total time including marshal

References

  • references/platforms/{platform}/cache.md