基于 EhCache 的缓存工具
| Type | Name and description |
|---|---|
static net.sf.ehcache.Ehcache |
createCache(String name, Boolean blocking = false)使用默认配置创建缓存,如果存在则直接返回。 |
static void |
disableCache(String name)禁用缓存 |
static void |
disableCache(net.sf.ehcache.Ehcache cache) |
static Object |
doWithBlockingCache(String name, java.io.Serializable key, Closure closure, Map options = null)创建一个 blocking 类型的缓存,执行闭包并将执行结果缓存下来。 |
static Object |
doWithBlockingCache(net.sf.ehcache.Ehcache cache, java.io.Serializable key, Closure closure, Map options = null) |
static void |
enableCache(String name)启用缓存 |
static void |
enableCache(net.sf.ehcache.Ehcache cache) |
static boolean |
evict(String name, java.io.Serializable key)@deprecated 使用 remove 代替 |
static void |
evictExpired()清理所有过期缓存 |
static Object |
get(String name, java.io.Serializable key)从缓存中获得值 |
static Object |
get(net.sf.ehcache.Ehcache cache, java.io.Serializable key) |
static net.sf.ehcache.Ehcache |
getCache(String name)// * TODO 创建本地缓存(不支持网络复制) // |
static net.sf.ehcache.CacheManager |
getCacheManager()获得 Ehcache 缓存管理器 |
static net.sf.ehcache.Ehcache |
getDefaultCache(String name) |
static net.sf.ehcache.CacheManager |
getDefaultCacheManager()获得 Hibernate 使用的默认 Ehcache 缓存管理器 |
static net.sf.ehcache.Element |
getElement(String name, java.io.Serializable key, boolean quiet = false)获得缓存元素 |
static net.sf.ehcache.Element |
getElement(net.sf.ehcache.Ehcache cache, java.io.Serializable key, boolean quiet = false) |
static List |
getKeys(String name)获得缓存的所有键值 |
static List |
getKeys(net.sf.ehcache.Ehcache cache) |
static boolean |
isCacheDisabled(String name)缓存是否已禁用 |
static boolean |
isCacheDisabled(net.sf.ehcache.Ehcache cache) |
static boolean |
put(String name, java.io.Serializable key, Object value, Map options = null)将键值对缓存,如果老缓存存在,会自动更新 |
static boolean |
put(net.sf.ehcache.Ehcache cache, java.io.Serializable key, Object value, Map options = null) |
static boolean |
remove(String name, java.io.Serializable key)删除一条缓存,并通知 CacheEventListener。 |
static boolean |
remove(net.sf.ehcache.Ehcache cache, java.io.Serializable key) |
static Integer |
removeAll(String name)清空缓存 |
static Integer |
removeAll(net.sf.ehcache.Ehcache cache) |
static Integer |
removeAll(String name, Closure keyFilter)清空特定的缓存 |
static Integer |
removeAll(net.sf.ehcache.Ehcache cache, Closure keyFilter) |
| Methods inherited from class | Name |
|---|---|
class Object |
Object#wait(long, int), Object#wait(long), Object#wait(), Object#equals(Object), Object#toString(), Object#hashCode(), Object#getClass(), Object#notify(), Object#notifyAll() |
使用默认配置创建缓存,如果存在则直接返回。
name - 缓存名称blocking - 缓存是否是blocking类型的,默认为否禁用缓存
创建一个 blocking 类型的缓存,执行闭包并将执行结果缓存下来。
name - 缓存名称key - 缓存条目的keyclosure - 可返回可序列化内容的闭包,其返回结果将被缓存options.refresh - 是否强制执行闭包、并更新缓存options.timeToLive - 缓存条目的生存期,覆盖默认设置,单位秒options.timeToIdle - 缓存条目的空闲期,覆盖默认设置,单位秒options.eternal - 缓存条目是否永久有效,覆盖默认设置启用缓存
清理所有过期缓存
从缓存中获得值
name - 缓存名称key - 缓存条目的key// * TODO 创建本地缓存(不支持网络复制) //
获得 Ehcache 缓存管理器
获得 Hibernate 使用的默认 Ehcache 缓存管理器
获得缓存元素
获得缓存的所有键值
缓存是否已禁用
将键值对缓存,如果老缓存存在,会自动更新
name - 缓存名称key - 缓存条目的keyvalue - 缓存条目的值options.blocking - 如果缓存名称对应的缓存不存在,如果存在则本参数无效;否则会先创建一个缓存,并根据本参数创建普通的缓存还是blocking的缓存options.timeToLive - 缓存条目的生存期,覆盖默认设置options.timeToIdle - 缓存条目的空闲期,覆盖默认设置options.eternal - 缓存条目是否永久有效,覆盖默认设置以及上面两个设置删除一条缓存,并通知 CacheEventListener。
name - 缓存名称key - 缓存条目的key清空缓存
name - 缓存名称清空特定的缓存
name - 缓存名称keyFilter - 过滤要清除的缓存key的闭包,如果返回true,则表明要清除该缓存,如 { key -> return key.startsWith("abc") }