[英]How to Evict less frequently used cache region periodicly?
According to this Ehcache_Configuration_Guide.pdf 根据此Ehcache_Configuration_Guide.pdf
How Configuration Affects Element Flushing and Eviction
配置如何影响元素冲洗和逐出
The following example shows a cache with certain expiration seings:以下示例显示了具有某些到期时间设置的缓存:
<cache name="myCache"
eternal="false" timeToIdleSeconds="3600"
timeToLiveSeconds="0" memoryStoreEvictionPolicy="LFU">
</cache>
Note the following about the myCache configuration:请注意有关myCache配置的以下内容:
If a client accesses an entry in myCache that has been idle for more than an hour timeToIdleSeconds), that element is evicted.如果客户端访问myCache中已闲置一个小时以上的条目timeToIdleSeconds,则该元素将被驱逐。
If an entry expires but is not accessed, and no resource constraints force eviction, then the expired entry remains in place until a periodic evictor removes it.如果条目过期但未被访问,并且没有资源约束强制驱逐,则过期的条目将保留在原处,直到定期驱逐者将其删除为止。
I didn't find any exemple of how to configure the eviction periodicly, 我没有发现如何定期配置驱逐的任何示例,
is it configurable? 它是可配置的吗? or it must be hard-coded for hibernate?
还是必须对它进行硬编码才能进入休眠状态?
According to this page ExpiryTaskExtension.java There is no default schedular for time eviction in ehCache 根据此页面, ExpiryTaskExtension.java在ehCache中没有默认的时间表来驱逐时间
import java.util.Timer;
import java.util.TimerTask;
import net.sf.ehcache.CacheManager;
public class EhCacheExpiryTask {
class ExpiryTask extends TimerTask{
@Override
public void run() {
for (CacheManager manager : CacheManager.ALL_CACHE_MANAGERS) {
for (String name : manager.getCacheNames()) {
//manager.getCache(name).getCacheConfiguration().setStatistics(true);
manager.getCache(name).evictExpiredElements();
}
}
}
}
private Timer timer;
private long period;
private ExpiryTask expiryTask;
public EhCacheExpiryTask(long period){
this.period = period;
this.timer = new Timer();
}
public void stop(){
timer.cancel();
}
public void start(){
expiryTask = new ExpiryTask();
timer.schedule(expiryTask, 10000, period);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.