I am setting up EHCache in hibernate project. What happens if the cache got full? Suppose there all the entities are valid in the cache and hibernate wants to add the new entity into it. Then which entity will be evicted by the hibernate to add this new entity into the cache? Or is there any mechanism to handle this situation by code?
The default implementation is LRU or least recently used. Of course this can be reconfigured, but generally this is not a bad policy. Documentation here. It would seem they also support LFU and FIFO, and you can specify your own algorithm should you so choose.
Good luck!