// Spring Boot + Caffeine integration fragment; supply repository and authorization. @Bean Cache cartCache() { return Caffeine.newBuilder() .maximumSize(10_000) .expireAfterAccess(Duration.ofMinutes(20)) .recordStats() .build(); } // CartKey includes tenant and cart identity. Authorize before cache access. CartSnapshot read(AuthenticatedUser user, CartKey key) { authorization.requireCartAccess(user, key); return cartCache.get(key, repository::loadImmutableSnapshot); } // Invoke AFTER successful commit, not before. Across pods use versioned reads // or a durable invalidation mechanism; local invalidation alone is insufficient. void afterCartCommit(CartKey key) { cartCache.invalidate(key); }