Reputation: 570
Refer to Spring Cache which can be used to cache the service calls.
Specially the following xml snippet:
<!-- 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>
The above mechanism works if the key is a single property. I need to cache based on isbn and author.
Can somebody suggest how can the caching be enabled using two properties?
Thanks
Upvotes: 0
Views: 1098
Reputation: 2687
you could easily use key="#author.toString() + #isbn.toString()")
or implement your own keyGenerator and configure it or you just omit the key attribute so that all arguments are taken into account.
Upvotes: 1