How to integrate Ehcache with Scala

Table of contents
Reading Time: 2 minutes

Ehcache is a widely used open source Java distributed cache for general purpose caching, Java EE and light-weight containers.

Ehcache was originally developed by Greg Luck, starting in 2003.In 2009, the project was purchased by Terracotta, who provides paid support.

For integrating Ehcache in scala steps are :

1) First we need to Download BigMemory GO from

2) Once it is downloaded we will get terracotta-license.key on our email which needs to be put in resource folder.

3) Put ehcache.xml in resource folder.

4) Add related jars in classpath .

a) ehcache-ee-2.7.5.jar
b) bigmemory-4.0.5.jar

Or add following library dependencies in build.sbt

Above steps will give you the access of configuring ehcache in scala.

Ehcache configuration : We can configure ehcache in two ways.

1) Declarative : We have to configure our cache region in ehcache.xml

Here maxEntriesLocalHeap are the total number of entries which a cache region can have.
Its default value is 0 which means our cache region can have any number of entries.

eternal and (timeToIdleSeconds , timeToLiveSeconds ) are vice versa means if eternal = true then there is no meaning of  timeToIdleSeconds and timeToLiveSeconds . Elements in cache region will not expire.

localTempSwap is a persistence strategy which write the data in disk but when you restart the system , this cache related data will automatically removes from the disk.

2) Programatically:

Example :

2 thoughts on “How to integrate Ehcache with Scala2 min read

Comments are closed.