Hi, according to documentation, Spring under the hood uses ConcurrentHashMap that as we know is unbounded and lacking TTL policy. While ConcurrentHashMap is a great choice for a demo application, it is harmful unless chosen consciously.
If a developer forget to configure a cache provider (like EhCache or Caffeine) before deployment, it will cause OutOfMemoryError after indeterminate amount of time. It happened couple of weeks ago in a company I work with, when one of our services crashed.
I would like to suggest a small change to configuration of Spring cache abstraction - developer should configure explicitly that is fine with the default config. I propose to make a SimpleCacheConfiguration dependent on spring.cache.type=simple setting. When spring.cache.type is missing, context should fail to start. WDYT?
Comment From: snicoll
Thank you for the suggestion but this would break users who are relying on that behaviour to cache a reasonable amount of data and are fine with the default behaviour of using an unbounded heap.
Comment From: mszarlinski
This is so sad as this is a recurring problem for production-grade applications.