首页 文章

@Cacheable - 禁用自动刷新

提问于
浏览
0

我在我的spring项目中实现了@Cacheable,我遇到了一个问题 .

当缓存启用并且它返回arraylist时 . 之后,我根据业务需求修改该列表 . 但是当我的缓存代码第二次出现并且它提供了我不需要的更新列表时 . 我只需要实际清单 .

那么,@ Cacheable注释中是否有任何功能可以禁用该自动更新?

请帮助我

谢谢,

2 回答

  • 0

    也许 @Cacheable 不能满足您的要求 .

    你可以使用 @CachePut

    @CachePut(value = "products", key = "#product.name" , unless="#result==null")
    public Product updateProduct(Product product) { }
    

    此批注用于缓存更新操作 . 上面的方法将在每次调用时执行,结果将存储在缓存中[除非#result,本例中的产品为null] .

  • 0

    我通过在ehcache.xml文件中添加copyOnRead =“true”copyOnWrite =“true”解决了这个问题:)

    <cache name="cacheName" eternal="false" maxElementsInMemory="100" overflowToDisk="false"
            diskPersistent="true" timeToIdleSeconds="0" timeToLiveSeconds="300"
            memoryStoreEvictionPolicy="LRU" statistics="true" copyOnRead="true" copyOnWrite="true"/>
    

相关问题