【问题标题】:Caching java.util.Map with ehcache使用 ehcache 缓存 java.util.Map
【发布时间】:2011-12-17 14:58:02
【问题描述】:

我正在使用 EHCache 和 Hibernate 来缓存我的数据库查询结果。 我正在使用 google annotations(com.googlecode.ehcache.annotations.Cacheable) 使 DAO 方法可缓存。

我的问题是,方法中的一个参数是java.util.Map,我不知道如何缓存它?

示例代码:

import com.googlecode.ehcache.annotations.Cacheable;
import com.googlecode.ehcache.annotations.KeyGenerator;
import com.googlecode.ehcache.annotations.PartialCacheKey;
import com.googlecode.ehcache.annotations.Property;

这里是示例方法

@Cacheable(cacheName = "ehcahe", keyGenerator = @KeyGenerator(name = "HashCodeCacheKeyGenerator", properties = @Property(name = "includeMethod", value = "false")))
public Object get( @PartialCacheKey Map map ) {
 //do something
}

有什么帮助吗?

【问题讨论】:

    标签: java hibernate spring ehcache


    【解决方案1】:

    您可以实现自己的CacheKeyGenerator,参见FAQ,问题7

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-20
      • 2012-08-15
      • 2016-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多