Skip to content

dev48v/cache-visualizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

⚡ Spring Cache Visualizer

Watch Spring's @Cacheable actually skip the database. A hit returns instantly, a miss loads and stores, entries expire on TTL, and @CachePut / @CacheEvict refresh or clear the cache. The cache-aside pattern (Redis / Caffeine style), made visible — with a live "DB calls saved" count.

▶ Live demo  ·  What it shows  ·  Run locally

License: MIT No dependencies Spring Cache


Why

@Cacheable is one annotation with a lot of invisible behaviour: when does it skip the method? what does @CachePut do differently? why did my cached value go stale — or never expire? This shows every hit, miss, store, and eviction on a live cache, so the mental model (and the cache-aside pattern behind it) clicks.

What it shows

  • @Cacheable hit vs miss — first getUser(1) is a miss: the DB runs (~800ms) and the result is cached. Call it again → hit: instant, and the method never runs. The "DB calls saved" counter is the whole point of caching in one number.
  • The cache-aside flow — Caller → @Cacheable proxy → check cache → (hit) return, or (miss) → Database → store → return. Animated each call.
  • @CachePut — always runs the method and refreshes the entry (watch the rev bump), without short-circuiting like @Cacheable.
  • @CacheEvict — removes one entry (next read misses again) or clears all (allEntries = true).
  • TTL expiry — entries show a countdown bar; after ~7s they expire and the next call reloads them. The classic "why is my cache stale / why does it never update" made obvious.

The gotchas it surfaces

  • @Cacheable skips your method entirely on a hit — so side effects in that method won't run when cached.
  • Self-invocation bypasses the cache — like @Transactional, calling a @Cacheable method from within the same bean skips the proxy, so nothing is cached.
  • @CachePut@Cacheable — Put always executes; Cacheable executes only on a miss.

Run it locally

open index.html          # macOS
start index.html         # Windows
python -m http.server 8000   # or serve → http://localhost:8000

Note

A teaching model — the @Cacheable/@CachePut/@CacheEvict semantics and cache-aside flow match Spring Cache (with Redis, Caffeine, or the simple ConcurrentMapCacheManager); data and timings are simulated.

Contributing

Ideas: @Cacheable(condition=…, unless=…), key generators, cache stampede / thundering-herd, two-level (L1 Caffeine + L2 Redis) caching. PRs welcome.

If this made Spring caching click, a ⭐ helps others find it.

License

MIT © dev48v

About

Watch Spring @Cacheable skip the database: hit/miss, cache-aside, TTL expiry, @CachePut/@CacheEvict, and a live DB-calls-saved count. Zero deps.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages