SECURITY WARNING: Never run commands you don't understand. Always review code before execution. Use at your own risk.
Caching New Added 26 October 2026

Spring: java.lang.IllegalArgumentException: Cannot find cache named 'users'

A @Cacheable, @CachePut or @CacheEvict annotation names a cache that the CacheManager does not know and will not create. Spring Boot's default simple cache creates caches on demand, so everything works until a real provider arrives: Caffeine with spring.cache.cache-names set, or a JCache provider such as Ehcache 3, treats that list as fixed and rejects every other name. It often fails in only one profile, the one where a different cache type is configured.

Quick fix

Read the commands before running them. Anything that restarts a service, deletes data or changes permissions should be tried on a non-production system first.

Quick fix
# Which caches does the running app know? (needs actuator, with
# management.endpoints.web.exposure.include=caches)
curl -s localhost:8080/actuator/caches

# Every cache name the code uses
grep -rnE "@(Cacheable|CachePut|CacheEvict|CacheConfig)" src/main/java

# Which cache type does each profile configure?
grep -rn "spring.cache" src/main/resources/ 2>/dev/null

# Caffeine: list every name, or leave cache-names unset to create on demand
# spring.cache.type=caffeine
# spring.cache.cache-names=users,orders,products
# spring.cache.caffeine.spec=maximumSize=10000,expireAfterWrite=10m

# JCache / Ehcache 3: add <cache alias="users"> to ehcache.xml

How to diagnose Caching errors

Cache problems are rarely reported as cache problems. They arrive as a traffic spike that takes down the origin (a stampede after a mass eviction), users seeing old content after a deploy, or an inexplicable 403 from the CDN. The unifying diagnostic is to look at the cache status header on a real response before theorising about anything else.

If the quick fix above does not resolve it, work through these steps. They apply to this whole class of error, not just to this one message, which is usually what saves the time.

  1. Read the cache status header on a live request: curl -sI https://example.com | grep -i -E 'cache|age|x-cache|cf-cache-status'. HIT, MISS and BYPASS each point at a different root cause.
  2. Check the Age header against your intended TTL. An Age larger than max-age means something is serving stale content deliberately (stale-while-revalidate), often the desired behaviour, occasionally the bug.
  3. For stampedes, add request coalescing or a short randomised TTL jitter rather than a longer TTL. Identical expiry times across many keys are what create the thundering herd.
  4. Use content-hashed filenames for static assets and no-cache for HTML. Almost every "users see the old version" incident traces back to a long TTL on an HTML document.
  5. For CDN 403s, distinguish a CDN-generated response from an origin one by checking whether CDN-specific headers are present. An origin 403 has a completely different fix.

Tools worth reaching for

  • curl -sI
  • varnishlog
  • CDN edge logs
  • Cache-Control validators

Authoritative references

Primary documentation for this error, worth reading before applying any fix in production.

docs.spring.io docs.spring.io

Related Caching errors

See all 20 Caching errors →

Browse other categories

Something missing or wrong?

This entry is maintained by hand. If the fix is out of date, incomplete, or you have a better one, email a correction and it will be reviewed.