Eviction policy

The eviction policy is what makes the cache different from a database or Map. It enables you to define how the data is automatically removed from the cache storage. This is very important because if you cache some reference data taken from a database, then the database storage can be bigger than the memory storage you have available on the machine and, thus, without any eviction, you will end up filling the memory and getting OutOfMemoryException instead of the performance boost you were expecting from the cache addition.

There are several kinds of eviction policies, but there are few mainstream categories:

  • Least Recently Used (LRU)
  • First In First Out (FIFO)
  • Random
  • Least Frequently Used (LFU)
Only LRU, FIFO, and Expire

Get Java EE 8 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.