Ehcache 3.9.2 LFU java configuration

1,292 views
Skip to first unread message

wm

unread,
Jun 1, 2021, 9:10:21 PM6/1/21
to ehcache-users
Hi,

Using EhCache 3.9.2, I was trying to set the memoryStoreEvictionPolicy to LFU
But, I am not able find any documentation that explains how I can set such configuration in Java or xml for the mentioned version of Ehcache.

Any suggestion on how I can override the default LRU with LFU will be much appreciated.

Thank you

Chris Dennis

unread,
Jun 2, 2021, 9:17:03 AM6/2/21
to ehcach...@googlegroups.com

In Ehcache 3 there is no way of choosing an eviction policy. Each tier within the cache {heap, offheap, disk, cluster} is free to choose the most appropriate eviction policy given it’s implementation. The heap tier operates a biased sampling LRU scheme, the offheap and cluster use an LRU clock. Given that both of these are sampling based and therefore neither strict LRU or LFU, it was decided that configurability here wasn’t worth the implementation cost and that the bulk of users wouldn’t need this fine-grained control.

 

Given the modularity within Ehcache 3 if an LFU policy is a hard requirement, it should be possible for someone to build their own LFU evicting store implementation and plug it in as a third-party provider.

 

Chris

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ehcache-users/48725490-ee59-468a-86c3-3abdfb2eba4bn%40googlegroups.com.

wm

unread,
Jun 2, 2021, 5:33:20 PM6/2/21
to ehcache-users
Thank you for your quick response and the details

wm

unread,
Jun 19, 2021, 3:14:32 PM6/19/21
to ehcache-users
Hello,

Based on the input I get here, I configured ehcache onheap with 200 entries count, and 1MB of maximum object size.
Does this mean that the max heap memory used will be 200MB ? or Should I have to explicitly use MB rather than entries in on heap resource pool configuration?

Thank you.
Wonde

Chris Dennis

unread,
Aug 2, 2021, 11:57:39 AM8/2/21
to ehcach...@googlegroups.com

Could you provide your actual cache configuration (either XML or Java code) to help clarify your question?

 

Thanks,

Wondwosen Eshetu

unread,
Aug 2, 2021, 5:28:13 PM8/2/21
to ehcach...@googlegroups.com
Hi Chris,

Here is the Java configuration.

ExpiryPolicy policy = ExpirationPolicyBuilder.timeToLiveExpiration(Duraton.ofMinutes(5));
ResourcePools resourcePools = ResourcePoolsBuilder.bewResourcePoolsBuilder()
             .heap(200, EntryUnit.ENTRIES)
CacheConfiguration cacheConfiguration = new CacheConfigurationBuilder( String, String, resourcePools)
        .withSizeOfMaxObjectSize(1, MemoryUnit.MB)
       .withExpiry(policy)
      .build();

CacheManager manager = CacheManagerBuilder.newCacheManagerBuilder()
            .withCache("cache1", cacheConfiguration)
           .build(true)

Thanks and regards,
Wonde

Chris Dennis

unread,
Aug 2, 2021, 8:58:32 PM8/2/21
to ehcach...@googlegroups.com
The max object size configuration here controls the point at which the size-of engine will abort when sizing an object graph. In your configuration however since the heap tier is count based this condition does essentially nothing. The cache will be be limited to 200 entries. How big each entry is will be entirely up to the application.

Chris

Reply all
Reply to author
Forward
0 new messages