Skip to Content
0
Nov 30, 2018 at 02:04 AM

How can I use different key generators for different web services methods?

68 Views

Assume that I have 1 ehcache CacheManager and a Controller with 2 methods.

Is it possible for Method 1 to use AlphaKeyGenerator, and Method 2 to use BravoKeyGenerator? By default, the methods use AlphaKeyGenerator.

I tried to create the Java class for BravoKeyGegenerator (which extends CommerceCacheKeyGenerator), and tried define it in Method 2's Cachable annotation, but Method 2 is still using AlphaKeyGenerator instead of BravoKeyGenerator. Is there additional XML configuration I need to do? I already defined the BravoKeyGenerator bean in customwebservices-spring.xml

Method 1:

 @Cacheable(value = "storeCache", key = "T(com.custom.commerce.webservices.cache.AlphaKeyGenerator).generateKey(false,false,'Data',#query,#latitude,#longitude,#currentPage,#pageSize,#sort,#radius,#accuracy)")
 public StoreFinderSearchPageData<PointOfServiceData> method1(final String query, final Double latitude,
         final Double longitude, final int currentPage, final int pageSize, final String sort, final double radius,
         final double accuracy)

Method 2:

 @Cacheable(value = "storeCache", key = "T(com.custom.commerce.webservices.cache.BravoKeyGenerator).generateKey(false,false,'Data',#query,#latitude,#longitude,#currentPage,#pageSize,#sort,#radius,#accuracy)")
 public StoreFinderSearchPageData<PointOfServiceData> method2(final String query, final Double latitude,
         final Double longitude, final int currentPage, final int pageSize, final String sort, final double radius,
         final double accuracy)