1. Cache Levels of System
  2. Caching Strategies
  3. Invalidation Strategies

Implementation Comparison

Most commonly used are:

  • Redis
  • Memcached
FeatureRedisMemcached
AgeMore recentOlder
Data StructuresStrings, lists, sets, sorted sets, hashes, bitmapsKey-value pairs (strings or binary data)
PersistenceOptionalIn-memory only
Atomic OperationsYes (e.g., increments, list manipulations)No
Pub/SubYesNo
High AvailabilityYes (but with additional services/resources)Yes (but with 3rd party solutions only)
ComplexityHIgher complexity (intrinsic to having more features and data structures)Simpler
Cache Eviction PolicyConfigurable (e.g., LRU, LFU i.e., least frequently used, etc.)Least Recently Used (LRU)
Use CasesReal-time needs, application cachingSimple caching, session storage
Companies UsingGitHub, Stack OverflowFacebook, YouTube, Reddit

Disadvantages

  • Requires maintaining consistency of data between caches and sources of truth (cache invalidation)
  • Cache invalidation is a notoriously difficult problem and can require significant investment to get right for a specific system and its constraints
  • Requires application changes to access cache