1

Below is configuration for ehcache,

Assume that we are using ehcache version 3.7

<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
        xmlns='http://www.ehcache.org/v3'
        xmlns:jsr107='http://www.ehcache.org/v3/jsr107'
        xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.7.xsd
                            http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.7.xsd">


    <service>
        <jsr107:defaults enable-management="true" enable-statistics="true"/>

    </service>

    <cache alias="MyCache">
        <expiry>
            <ttl unit="seconds" >172800</ttl>
        </expiry>
        <heap unit="entries">1000</heap>

    </cache>




</config>
  1. Question is: How to switch to TickingTimeSource, as mentioned in ehcache documentation here

Homework done so far:-

  • Tried to search for configuration tag for TickingTimeSource within ehcache xsd file --> no clues so far.
  • Searched for TickingTimeSource switching within ehcache 3 codebase for sample code in github --> no clues so far.
  • Just trying to squeeze performance hack with configurations on new ehcache 3. Found that LRU eviction policy is not supported in ehcache 3 . There is AgainstEvictionAdvisor ( logic to prevent eviction, this would'nt help in performance I guess )
  • Checked for answer to similar query in ehcache google groups -> No answer so far
  • Checked for sample ehcache configuration gists file from github -> Did not find relevant config for TickingTimeSource so far.
  • Did a java code debug where ehcache is used and check internal variables/ objects and search for setting TimeSource - this might give clue to inject TickingTimeSource probably. Found that, TimeSource needs to be set in internal Store object ( JSR107Store or ehcacheStore ), but it does not provide api to set the timesource directly.
a3.14_Infinity
  • 5,653
  • 7
  • 42
  • 66

1 Answers1

0

I found only a way to achieve this through the Java-based configuration. I haven't had time to test this, but this code is similar to what I found in ehcache tests:

CacheManager cacheManager =
    CacheManagerBuilder.newCacheManagerBuilder()
            .using(new TimeSourceConfiguration(new TickingTimeSource(1L, 1000L)))
            .withCache("cache1",
                    CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, Object.class, ResourcePoolsBuilder.heap(10))).build(true)
Nikola
  • 1,406
  • 2
  • 16
  • 20