请参考可用于缓存服务调用的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和作者。
有人能建议如何使用两个属性来启用缓存吗?
谢谢
发布于 2016-07-29 03:52:04
您可以轻松地使用key="#author.toString() + #isbn.toString()")或实现自己的keyGenerator并对其进行配置,或者只需省略关键属性,以便将所有参数都考虑在内。
https://stackoverflow.com/questions/38644514
复制相似问题