daily pastebin goal
39%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Cacheable(value="bookCache", key="isbn")
  2. public Book findBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed)
  3.    
  4. System.out.println( Objects.hash("someisbn", new Integer(109), new Integer(434)));
  5.     System.out.println( Objects.hash("someisbn", new Integer(110), new Integer(403)));
  6.    
  7. @Cacheable(value="books", key="T(someType).hash(#isbn)")
  8. public Book findBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed)
  9.    
  10. @Cacheable(value="bookCache",
  11.   key="{ #root.methodName, #isbn?.id, #checkWarehouse }")
  12. public Book findBook(ISBN isbn, boolean checkWarehouse)
  13. ...
  14.  
  15. @Cacheable(value="bookCache",
  16.   key="{ #root.methodName, #asin, #checkWarehouse }")
  17. public Book findBookByAmazonId(String asin, boolean checkWarehouse)
  18. ...
  19.    
  20. <cache:annotation-driven mode="..." key-generator="cacheKeyGenerator" />
  21. <bean id="cacheKeyGenerator" class="net.example.cache.CacheKeyGenerator" />
  22.    
  23. public class CacheKeyGenerator
  24.   implements org.springframework.cache.interceptor.KeyGenerator {
  25.  
  26.     @Override
  27.     public Object generate(final Object target, final Method method,
  28.       final Object... params) {
  29.  
  30.         final List<Object> key = new ArrayList<>();
  31.         key.add(method.getDeclaringClass().getName());
  32.         key.add(method.getName());
  33.  
  34.         for (final Object o : params) {
  35.             key.add(o);
  36.         }
  37.         return key;
  38.     }
  39. }
  40.    
  41. @Cacheable(value="bookCache", key="T(java.util.Objects).hash(#p0,#p1, #p2)")
  42.    
  43. @Cacheable(value="bookCache", key="#checkwarehouse.toString().append(#isbn.toString())")
  44.    
  45. @Cacheable(value="bookCache", key="isbn + '_' + checkWarehouse + '_' + includeUsed")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top