gpt4 book ai didi

java - 使用 ehcache 缓存 java.util.Map

转载 作者:行者123 更新时间:2023-12-01 15:40:44 25 4
gpt4 key购买 nike

我将 EHCache 与 Hibernate 结合使用来缓存我的数据库查询结果。我正在使用 google 注释(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
}

有什么帮助吗?

最佳答案

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

关于java - 使用 ehcache 缓存 java.util.Map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8076519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com