Over a million developers have joined DZone.

Ehcache Size Configuration

· Java Zone

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

Since Ehcache 2.5, you’ve got Automatic Resource Control (ARC), which help you to easily tune your cache.

When you think that software is constantly changing, let’s say you have a class that takes 1Kb when instantiated, then you put 1000000 elements in a cache, it takes 1Gb. After a few releases, the class has been modified, it has more fields, and it takes now 2Kb when instantiated, the exact same cache definition will take 2Gb…

ARC helps you to define a cache by memory size. In this example you say you want your cache to use 1Gb of heap memory, it will first hold 1M elements, then 500000… Your tuning is automatically handled…

In case you want to have a look at ARC vs count-based config, here is a summary of options you can use:

Standalone – Cache Configuration

  Count-based Count-based – legacy pre-2.5 Size-based (ARC)
Heap maxEntriesLocalHeap maxElementsInMemory (deprecated) maxBytesLocalHeap
Off heap maxMemoryOffHeap maxMemoryOffHeap maxBytesLocalOffHeap
Disk maxEntriesLocalDisk maxElementsOnDisk maxBytesLocalDisk

Clustered – Cache Configuration

  Count-based Count-based – legacy pre-2.5 Size-based (ARC)
Heap maxEntriesLocalHeap maxElementsInMemory (deprecated) maxBytesLocalHeap
Off heap maxMemoryOffHeap maxMemoryOffHeap maxBytesLocalOffHeap
Disk NA maxElementsOnDisk NA

more info on Ehcache ARC

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:

Published at DZone with permission of Aurelien Broszniowski, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}