gpt4 book ai didi

java - 如何使用两个属性作为key的spring缓存

转载 作者:行者123 更新时间:2023-12-01 09:38:27 25 4
gpt4 key购买 nike

引用Spring Cache可用于缓存服务调用。

特别是以下 xml 片段:

<!-- the service we want to make cacheable -->
<bean id="bookService" class="x.y.service.DefaultBookService"/>

<!-- cache definitions -->
<cache:advice id="cacheAdvice" cache-manager="cacheManager">
<cache:caching cache="books">
<cache:cacheable method="findBook" key="#isbn"/>
<cache:cache-evict method="loadBooks" all-entries="true"/>
</cache:caching>
</cache:advice>

<!-- apply the cacheable behavior to all BookService interfaces -->
<aop:config>
<aop:advisor advice-ref="cacheAdvice" pointcut="execution(* x.y.BookService.*(..))"/>
</aop:config>

如果键是单个属性,则上述机制有效。我需要根据 isbn 和作者进行缓存。

有人可以建议如何使用两个属性启用缓存吗?

谢谢

最佳答案

您可以轻松使用 key="#author.toString() + #isbn.toString()") 或实现您自己的 keyGenerator 并配置它,或者您只需省略 key 属性,以便所有考虑参数。

关于java - 如何使用两个属性作为key的spring缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38644514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com