I can't set expiry of second level cache with Ehcache.
Is there any way to config expiry?
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'org.hibernate:hibernate-jcache:5.6.5.Final'
implementation 'org.ehcache:ehcache:3.9.9'
spring:
jpa:
properties:
javax:
persistence:
sharedCache:
mode: ENABLE_SELECTIVE # Enable caches only @Cacheable annotated classes
hibernate:
cache:
use_query_cache: true
use_second_level_cache: true
region:
factory_class: org.hibernate.cache.jcache.JCacheRegionFactory
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Cacheable
@Cache(region = "test_cache", usage = CacheConcurrencyStrategy.READ_WRITE)
public class Test {
.
.
.
}
Yes, there is a way.
factory_class
to org.hibernate.cache.ehcache.EhCacheRegionFactory
ehcache.xml
in /src/main/resources
with this content: ...
<cache-template name="default">
<expiry>
<ttl unit="hours">48</ttl>
</expiry>
</cache-template>
...
Details to the XML configuration can be found at https://www.ehcache.org/documentation/3.9/xml.html