介绍暂时不写,先粘贴一个常用用法。
public class GeneralUserCache {
private Cache<Long, GeneralUser> userCache = Caffeine.newBuilder().maximumSize(1000).expireAfterWrite(3, TimeUnit.DAYS).build();
public GeneralUser getUser(Long id){
if(id == null){
return null;
}
GeneralUser user = userCache.get(id, new Function<Long, GeneralUser>() {
@Override
public GeneralUser apply(Long aLong) {
GeneralUser user = new GeneralUser();
user.setId(id);
user.setName(getUserName(id));
return user;
}
});
return user;
}
}