jetcache 关于缓存穿透的配置项加载优先级问题

fafcakar  于 2022-12-31  发布在  其他
关注(0)|答案(2)|浏览(325)

今天在阅读源码调试使用的时候发现使用CacheBuilder方法的cachePenetrateProtect(true)时,并没有使用我配置的value,debug跟踪了一下,发现在com.alicp.jetcache.anno.support.CacheContext的138行执行了cache.config().setCachePenetrationProtect(globalCacheConfig.isPenetrationProtect());,这个全局的配置默认value是false,但是其实我针对缓存配置的已经是true了。我理解的是关于CacheConfig类的cachePenetrationProtect默认值是不是使用null更为合理?这样可以避免配置了缓存个性化的配置,会被全局配置覆盖掉,当然我这里这个配置没有使用基于方法的注解,而是在初始化缓存构建的时候直接配置的。
`@Bean
public GlobalCacheConfig config(Pool pool){
Map localBuilders = new HashMap();
EmbeddedCacheBuilder localBuilder = LinkedHashMapCacheBuilder
.createLinkedHashMapCacheBuilder()
.keyConvertor(FastjsonKeyConvertor.INSTANCE)
.cachePenetrateProtect(true);//这样配置会被globalCacheConfig覆盖
localBuilders.put(CacheConsts.DEFAULT_AREA, localBuilder);

Map remoteBuilders = new HashMap();
    RedisCacheBuilder remoteCacheBuilder = RedisCacheBuilder.createRedisCacheBuilder()
            .keyConvertor(FastjsonKeyConvertor.INSTANCE)
            .valueEncoder(KryoValueEncoder.INSTANCE)
            .valueDecoder(KryoValueDecoder.INSTANCE)
            .jedisPool(pool)
            .cachePenetrateProtect(true);//这样配置会被globalCacheConfig覆盖
    remoteBuilders.put(CacheConsts.DEFAULT_AREA, remoteCacheBuilder);

    GlobalCacheConfig globalCacheConfig = new GlobalCacheConfig();
    globalCacheConfig.setLocalCacheBuilders(localBuilders);
    globalCacheConfig.setRemoteCacheBuilders(remoteBuilders);
    globalCacheConfig.setStatIntervalMinutes(0);
    globalCacheConfig.setAreaInCacheName(false);
    //globalCacheConfig.setPenetrationProtect(true);
    return globalCacheConfig;
}`
vsikbqxv

vsikbqxv1#

这里补充下,什么时候能考虑下把@CachePenetrationProtect注解的功能配置,加到@CreateCache的配置里面呢?

wwodge7n

wwodge7n2#

这里补充下,什么时候能考虑下把@CachePenetrationProtect注解的功能配置,加到@CreateCache的配置里面呢?

@CreateCache注解的字段可以添加@CachePenetrationProtect字段

相关问题