Knowledgebase

Caching in Backend Systems Print

  • backenddevelopment, backend, caching, domainrenewal, troubleshooting, guide, howto, solution
  • 0

Avoiding repeated work.

WHAT TO CACHE

Expensive computations Frequently repeated queries External responses that change rarely Rendered fragments

WHAT NOT TO CACHE

Data that must always be current Personal data, in a shared cache

WHAT THE STRATEGIES ARE

  • Read through: check the cache, fall back to the source
  • Write through: update both on write
  • Write behind: update the cache, persist later

WHAT THE HARD PROBLEM IS

Invalidation.

WHAT TO DECIDE FOR EACH ENTRY

How stale it may be What invalidates it

WHAT TO PREFER WHERE POSSIBLE

Expiry, which is simple and self-correcting.

WHAT TO BE CAREFUL WITH

Many entries expiring simultaneously, causing a surge on the source Caching failures Cache keys that collide

WHAT TO DO ABOUT THAT FIRST ONE

Vary expiry slightly between entries.

WHAT TO MEASURE

Hit rate, and whether load actually reduced.

WHY

A cache with a poor hit rate adds complexity for nothing.

WHAT TO ENSURE

That the system works correctly when the cache is empty or unavailable.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot