Query Cache vs App Cache
Cache layers.
Overview
Query cache and app cache solve different problems at different layers. Query cache memoises database results; app cache memoises business-logic objects. Stacking both costs storage and complexity; picking the right layer per use case is what wins.
- Cache layers per data type. Read-heavy database queries fit query cache; computed business objects fit app cache. Different data shapes select different layers.
- Query cache: per-query. Result cache keyed on the query string and parameters. Hits return immediately; misses fall through to the database.
- App cache: per-object. Business-logic objects cached after computation. Hits skip the entire compute path, not just the database read.
- Per-tier invalidation plus documented layers. Each tier needs its own invalidation strategy; the cache layout per service lives in the runbook.
The approach
Three habits keep caching strategy coherent: pick the layer per data type, write down the invalidation strategy, and monitor hit rate as a standing signal.
- Per-data cache layer. Database results to query cache; computed objects to app cache. Avoid double-caching the same data at both layers.
- Per-tier invalidation. TTL-based for read-heavy stable data; event-driven for fast-changing data. Pick the strategy that matches consistency needs.
- Documented strategy. Per-cache rationale lives next to the cache code. Future operators inherit the design intent.
- Hit rate plus freshness target. Monitor cache hit rate; declare a freshness target per cache that the invalidation strategy must meet.
Why this compounds
Each correctly-placed cache produces ongoing performance benefit. The team learns caching through repeated decisions; new services ship with cache layouts that match the data shape from day one.
- Performance. Right cache layer matches workload. The wrong layer adds latency without benefit.
- Cost efficiency. Right cache reduces backend load. Database compute and app compute both shrink.
- Operational fit. Right invalidation matches consistency requirements. Stale-data incidents shrink.
- Year-one investment, year-two habit. The first cache layout is investment. By the third service, the patterns are reflexive.