public abstract class CacheUtils extends Object
Modifier and Type | Method and Description |
---|---|
static <T extends Serializable> |
get(ICache cache,
String cacheKey,
boolean putTempToCacheIfNull,
FirsthandCreater<T> firsthandCreater)
根据cacheKey从缓存中获取对象,如果缓存中没有该key对象,则用firsthandCreater获取对象,并将对象用cacheKey存于cache中
|
static <T extends Serializable> |
get(ICache cache,
String cacheKey,
boolean putTempToCacheIfNull,
FirsthandCreater<T> firsthandCreater,
Long readTimeoutWithSeconds) |
static <T extends Serializable> |
get(ICache cache,
String cacheKey,
FirsthandCreater<T> firsthandCreater)
根据cacheKey从缓存中获取对象,如果缓存中没有该key对象,则用firsthandCreater获取对象,并将对象用cacheKey存于cache中
|
static <T extends Serializable> |
get(Long timeToLiveSeconds,
Long timeToIdleSeconds,
String cacheKey,
boolean putTempToCacheIfNull,
FirsthandCreater<T> firsthandCreater)
根据cacheKey从缓存中获取对象,如果缓存中没有该key对象,则用firsthandCreater获取对象,并将对象用cacheKey存于cache中
timeToLiveSeconds和timeToIdleSeconds一个传null一个传值
|
static <T extends Serializable> |
get(Long timeToLiveSeconds,
Long timeToIdleSeconds,
String cacheKey,
FirsthandCreater<T> firsthandCreater)
根据cacheKey从缓存中获取对象,如果缓存中没有该key对象,则用firsthandCreater获取对象,并将对象用cacheKey存于cache中
|
static CaffeineCache |
getCaffeineCache(Long timeToLiveSeconds,
Long timeToIdleSeconds)
根据参数获取或创建CaffeineCache对象
|
static CaffeineRedisCache |
getCaffeineRedisCache(org.redisson.api.RedissonClient redisson,
Long timeToLiveSeconds,
Long timeToIdleSeconds) |
static void |
main(String[] args) |
public static <T extends Serializable> T get(Long timeToLiveSeconds, Long timeToIdleSeconds, String cacheKey, FirsthandCreater<T> firsthandCreater)
timeToLiveSeconds
- timeToIdleSeconds
- cacheKey
- firsthandCreater
- public static <T extends Serializable> T get(Long timeToLiveSeconds, Long timeToIdleSeconds, String cacheKey, boolean putTempToCacheIfNull, FirsthandCreater<T> firsthandCreater)
timeToLiveSeconds
- timeToIdleSeconds
- cacheKey
- 请业务侧保证cacheKey的唯一性,建议的做法是由prefix + key组成,譬如"user.124578",其中user就是prefix,124578就是keyputTempToCacheIfNull
- 当FirsthandCreater获取不到对象时,是否使用临时对象,以防缓存攻击。true:可以防止缓存null攻击firsthandCreater
- public static <T extends Serializable> T get(ICache cache, String cacheKey, FirsthandCreater<T> firsthandCreater)
cache
- cacheKey
- firsthandCreater
- public static <T extends Serializable> T get(ICache cache, String cacheKey, boolean putTempToCacheIfNull, FirsthandCreater<T> firsthandCreater)
cache
- cacheKey
- putTempToCacheIfNull
- 当FirsthandCreater获取不到对象时,是否使用临时对象,以防缓存攻击。true:可以防止缓存null攻击firsthandCreater
- public static <T extends Serializable> T get(ICache cache, String cacheKey, boolean putTempToCacheIfNull, FirsthandCreater<T> firsthandCreater, Long readTimeoutWithSeconds)
T
- cache
- cacheKey
- putTempToCacheIfNull
- firsthandCreater
- readTimeoutWithSeconds
- 获取读锁的超时时间public static CaffeineCache getCaffeineCache(Long timeToLiveSeconds, Long timeToIdleSeconds)
timeToLiveSeconds
- timeToIdleSeconds
- public static CaffeineRedisCache getCaffeineRedisCache(org.redisson.api.RedissonClient redisson, Long timeToLiveSeconds, Long timeToIdleSeconds)
public static void main(String[] args)
Copyright © 2021. All rights reserved.