我们将
请问有人能告诉我们如何使缓存保持指定的时间段吗?
<time-to-live-seconds>
配置为1200(20分钟),但缓存在创建时间后一分钟就自动失效了。请问有人能告诉我们如何使缓存保持指定的时间段吗?
<time-to-live-seconds>
配置为1200(20分钟),但缓存在创建时间后一分钟就自动失效了。hazelcast.xml
中的以下代码片段将"simpleMap"内条目的time-to-live-seconds
属性设置为150秒。150秒以上未更新的旧条目将自动从地图中清除。请保留HTML标记,不需要解释。<map name="simpleMap">
<backup-count>0</backup-count>
<max-idle-seconds>0</max-idle-seconds>
<eviction-policy>LRU</eviction-policy>
<time-to-live-seconds>30</time-to-live-seconds>
<max-size>3000</max-size>
<eviction-percentage>30</eviction-percentage>
<merge-policy>com.hazelcast.map.merge.PutIfAbsentMapMergePolicy</merge-policy>
</map>
为了测试,我已经将一个entry listener附加到“simpleMap”上(如果使用的是3.5版本,请使用MapListener接口),当从映射中逐出一个条目时,它会打印出键和值。
public static void main(String[] args)
{
HazelcastInstance instance = HazelcastHelper.getHazelcastInstance();
IMap<String, String> map = instance.getMap("simpleMap");
map.addEntryListener(new SimpleMapEntryListener(), true);
map.put("evictme", "value");
printTime();
try {
Thread.sleep(1000 * 60);
} catch (InterruptedException e) {
e.printStackTrace();
}
printTime();
}
private static void printTime()
{
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
System.out.println( sdf.format(cal.getTime()) );
}
class SimpleMapEntryListener implements EntryListener<String, String>
{
@Override
public void entryEvicted(EntryEvent<String, String> arg0)
{
System.out.println("Key : " + arg0.getKey() + " Value: " + arg0.getOldValue() + " evicted.");
// print current time here.
}
// Add other overriden methods.
}