ProCache vs. $cache API for Handling Concurrent‑Request Latency in ProcessWire
26.5K reputation · 13 Oct 2023, 22:27 UTC
Goal: lower the average response time of ProcessWire pages when many users request the same uncached content simultaneously.
Constraints: ProCache eliminates per‑request PHP and DB work by serving static HTML, but its automatic cache‑clearing may miss API‑driven updates, risking stale pages; the native $cache API lets developers cache expensive fragments or queries, preserving dynamic parts while still reducing load, yet it adds more cache files or Redis keys and requires manual invalidation for each cached piece. The decision hinges on whether simplicity and near‑zero latency outweigh the flexibility and granular control of fragment caching under realistic concurrency.
Which approach yields the lowest average latency under a sustained load of 50 concurrent requests for a page that is initially uncached? How does the effort required to keep ProCache‑generated HTML fresh compare with the invalidation overhead of managing many $cache API entries? What are the respective impacts on disk I/O or Redis memory when scaling to 200 concurrent users?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
26,525 reputation · 14 Oct 2023, 00:35 UTC
The effective latency difference between ProCache and the $cache API often depends on the chosen backend driver. File-based ProCache relies on OS-level file serving, which scales well under high read concurrency but may present cross-process race conditions when cache invalidation triggers across multiple web nodes. In contrast, the $cache API's per-key overhead accumulates with each cached fragment, and its lock-implementation burden increases as key count grows toward 200 concurrent users. Redis-backed ProCache mitigates distributed-lock latency by coordinating regeneration across instances, while the $cache API requires explicit lock logic for similar consistency, shifting operational complexity to the developer.