Some things that Ehcache can give you are that you have to manage yourself using a HashMap.
Eviction Policy. If your data never grows, then you need not worry. But if you want to prevent a memory leak that will ultimately break your application, you need an eviction policy. With ehcache, you can set the time for live and the time for idle items in your cache.
Clustered caching with terracotta. If you have more than one tomcat to switch to another resource / scalability, you can link Ehcache to the Terracotta cluster so that all instances can see the same data, if necessary.
Transparent disk overflow - whether on a tomcat server or on a terracotta cluster. When data does not fit into the heap.
Inactive heap storage. New technologies, such as BigMemory, mean that you have access to a much larger cache in memory without GC overhead.
Concurrency. Ehcache can use ConcurrentDistributedMap to provide optimal performance in a clustered configuration.
This is just the tip of the iceberg.
toolkit
source share