The custom eviction algorithm (Advanced)

In this recipe, we will cover the following topics:

  • What an eviction algorithm is and how it works
  • Creating custom eviction algorithms using Ehcache

We will examine how to implement a custom eviction algorithm for our cached objects. We will re-use the Ehcache library classes as the basis for our own eviction algorithm.

Getting ready

Eviction algorithms are used to determine when to evict (or simply eject) an element from the cache layer when a certain condition has been met (for example, its life duration).

Ehcache also provides built-in eviction algorithms that you can use. However, there may be scenarios where you will want to control how to eject cached objects, and may want your code to react upon specific ...

Get Instant Effective Caching with Ehcache now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.