[英]how to use spring cache with two properties as key
请参考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和author进行缓存。
有人可以建议如何使用两个属性启用缓存吗?
谢谢
您可以轻松地使用key="#author.toString() + #isbn.toString()")
或实现自己的keyGenerator并对其进行配置,或者您只需省略key属性,以便将所有参数都考虑在内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.