Skip to content

Throttle cache stats writes to avoid per-request option updates #82

@mehul0810

Description

@mehul0810

Finding

StatsStore::flush() writes the full perform_cache_stats option whenever any stat changes, and page-cache hit/miss/bypass paths call stat increments during normal frontend traffic.

Evidence

  • src/Modules/Cache/PageCache.php increments and flushes stats on cache hits/stale hits, misses, lock waits, bypasses, and slow uncached requests.
  • src/Modules/Cache/StatsStore.php persists those changes with update_option( 'perform_cache_stats', ... , false ) in flush().

Impact

A busy site can turn otherwise cheap cached page views into frequent database writes. That undermines the page-cache module's main performance goal and can become a release-blocking scalability regression on high-traffic installs.

Suggested fix

Batch or sample observability writes instead of updating the option on every request. Reasonable options include a transient-backed throttle, periodic cron flush, in-memory aggregation per request class, or only writing top-miss/slow maps when thresholds change.

Acceptance criteria

  • Cache HIT/STALE/BYPASS traffic does not write perform_cache_stats on every request.
  • Observability counters remain useful after batching.
  • Existing option keys are preserved for backward compatibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: cachePage cache, menu cache, preload, invalidation, observability, or cache settings.area: performancePerformance-sensitive behavior, page weight, caching, preloading, or resource hints.bugConfirmed or likely defect affecting runtime behavior, UX, compatibility, or data handling.priority: highImportant for the next planned release or high user impact.risk: release-blockerShould be resolved or explicitly deferred before the target release ships.status: in-progressWork has a branch, PR, or active release branch implementation path.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions