java - Set up both TTL and TTI in Ehcache 3 XML configuration -


what trying accomplish set both ttl (time live) , tti (time idle) cache, key either expires after ttl time or can expired earlier in case in hasn't been accessed tti period.

in ehcache 2 possible following configuration:

<cache name="my.custom.cache"        timetoidleseconds="10"        timetoliveseconds="120"> </cache> 

in ehcache 3 analogous configuration block looks following:

<cache alias="my.custom.cache">     <expiry>         <tti unit="seconds">10</tti>         <ttl unit="minutes">2</ttl>     </expiry> </cache> 

the problem such configuration considered invalid since ehcache.xsd states there should one option under expiry tag (either tti or ttl, not both).

as mentioned louis jacomet on mailing list:

in order achieve want, need create custom expiry, can expirations.builder() introduced in 3.3.1, or custom implementation of expiry interface.

note explanation of expiration did in ehcache 2 incorrect. when combine ttl , tti, element remains valid whole ttl whether accessed or not. however, if accessed close end of ttl period, last access time + tti can make stay longer in cache. , if access again during period, last access time updated again extending life of mapping.

the way expiry works in ehcache 3 different, compute expiration time each time mapping created, accessed or updated. done reduce overhead in stored mappings.

so if configure expiry getexpiryforcreation returning 120 seconds getexpiryforaccess returning 10 seconds, created never access element considered expired after 120 seconds. while created accessed element considered expired 10 seconds after last access, if time still within 120 seconds. tti weird concept when think it, kept jcache compatibility, closer eviction expiration. because mean freshness of value being read? while indeed means useful value in cache should not evicted.

and in xml, cannot use tti , ttl shortcut in combination. can configure expiry qualified class name. should consider extending xml system can equivalent of added builder in code.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -