【问题标题】:Update item inside the cache and then call again findAll items doesn't update the item更新缓存中的项目,然后再次调用 findAll 项目不会更新项目
【发布时间】:2017-09-28 21:28:26
【问题描述】:

我创建了两个使用Spring Cacheservices。在第一种方法中,我将在应用程序启动时记录所有记录:

   @CachePut(value = "items")
    public Item save(Item item){
        System.out.println("----------------- z cachea udated" + item);
        return itemRepository.saveAndFlush(item);
    }

因此,当应用程序在最初的步骤中运行时,我会填充我的 cache。然后我得到所有记录:

 @Cacheable(value = "items")
    public Page<Item> getItems(Pageable pageRequest){
        System.out.println("----------------- z cachea PAGEABLE");

        Page<Item> all = itemRepository.findAll(pageRequest);
        System.out.println("----------------- all" + all.getContent());
        return all;
    }

然后我使用save() 方法只更新一条记录并再次获取所有记录。在那一刻,我的cache 根本没有改变。在cache 中,所有记录都在第一次调用方法中。如何只更改cache 中受更新影响的记录?

【问题讨论】:

    标签: java spring list caching spring-cache


    【解决方案1】:

    尝试将@Cacheable(value = "items") 更改为@Cacheable(value="items", key="all")

    【讨论】:

    • 这是一个很差的解决方案,因为它会导致错误。我试过了。。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-07
    相关资源
    最近更新 更多