cache本地缓存

1.google的guava的cache

线程安全的,易用的本地内存缓存。

1.1 依赖



    com.google.guava
    guava
    20.0-hal


1.2 类与方法

com.google.common.cache.Cache

接口声明。
void com.google.common.cache.Cache. put(K key, V value)
放入元素,若key存在,旧值被覆盖。
V com.google.common.cache.Cache. getIfPresent(Object key)

若存在返回V,不存在返回null。

构造cache的代码见下:

private Cache failureCache=CacheBuilder.newBuilder()
            .maximumSize(10*10000)
            .expireAfterWrite(3, TimeUnit.MINUTES)
            .build();


你可能感兴趣的:(Java-EE)