Always Generated New Keys, so not use cache

57 views
Skip to first unread message

Minsoo,song

unread,
Nov 1, 2012, 9:40:05 PM11/1/12
to ehcache-sprin...@googlegroups.com
hi~
 
I use ehcache-spring-annotations.
 
  <dependency>
   <groupId>com.googlecode.ehcache-spring-annotations</groupId>
   <artifactId>ehcache-spring-annotations</artifactId>
   <version>1.2.0</version>
  </dependency>
 
 
manager use annotations
 
@Cacheable(cacheName="GoodsManagerCache")
public List<Goods> findGoods(GoodsSearchCommand cmd) {
 
}
 
call log
 
Adding CACHE advised method 'findGoods' with attribute: CacheableAttributeImpl [cacheInstanceResolver=com.googlecode.ehcache.annotations.resolver.SingletonCacheableCacheResolver@1b219665, cacheKeyGenerator=HashCodeCacheKeyGenerator [includeMethod=true, includeParameterTypes=true, useReflection=false, checkforCycles=false], parameterMask=ParameterMask [mask=[]], cacheNull=true, cacheInterceptor=com.googlecode.ehcache.annotations.DefaultCacheableInterceptor@5a2d13c1]
Generated key '-221625528930174' for invocation: ReflectiveMethodInvocation: public abstract java.util.List
Generated key '-221626328636153' for invocation: ReflectiveMethodInvocation: public abstract java.util.List
 
 
always new key.
 
GoodsSearchCommand {
private Product product;
private Goods goods;
.....
}
 
help me please.
 

Eric Dalquist

unread,
Nov 1, 2012, 9:59:39 PM11/1/12
to ehcache-sprin...@googlegroups.com
Did you define hashCode and equals on every object in the data model used as the key? If not then instance equality is used by the JVM.

Minsoo,song

unread,
Nov 1, 2012, 10:41:54 PM11/1/12
to ehcache-sprin...@googlegroups.com
I use spring framework  @ModelAttribute
 
always new command object.
 
not use caches?
 
 @RequestMapping("/findGoods")
 public String goodsHandle(
   @ModelAttribute GoodsSearchCommand cmd,
   @ModelAttribute Goods goods,
   @ModelAttribute GoodsStock goodsStock,
   @ModelAttribute Seller seller,
   HttpServletRequest request, 
   ModelMap model) {
  cmd.setGoods(goods);
  cmd.getGoods().setGoodsStock(goodsStock);
  cmd.getGoods().setSeller(seller);
  
  List<Goods> goodsList=null;
  goodsList = goodsManager.findGoods(cmd); 
}
 

2012년 11월 2일 금요일 오전 10시 40분 6초 UTC+9, Minsoo,song 님의 말:

Eric Dalquist

unread,
Nov 1, 2012, 10:56:38 PM11/1/12
to ehcache-sprin...@googlegroups.com

Minsoo,song

unread,
Nov 2, 2012, 2:36:43 AM11/2/12
to ehcache-sprin...@googlegroups.com
thank you (;
Reply all
Reply to author
Forward
0 new messages