Fast where it matters
An in-process Caffeine copy (L2) sits in front of shared Redis (L1). An L2 hit is a map lookup and a time check, with no I/O.
Local-memory reads, Redis-shared state, and a hard bound on how stale any copy can get. For Java and Kotlin on Spring Boot.
@CoCache(ttl = 600) // seconds
interface UserCache : Cache<String, User>
@Bean // the data source, matched by type
fun userLoader(repo: UserRepository) = CacheLoader<String, User> { id -> repo.findById(id) }
@EnableCoCache(caches = [UserCache::class])
@SpringBootApplication
class App
// anywhere
val user = userCache["42"] // L2 → Redis → loader
invalidator.invalidate(userCache, "42") // after the commit, on every instance