什么时候应该在Ehcache中重新使用缓存,何时应该创建一个新缓存?何时使用新的缓存名称?
实施例1:
我有以下方法:
public Dog getBestDog(String name) {
//Find the best dog with the provided name
}
public Dog getBestBrownDog(String name) {
//Find the best brown dog with the provided name
}
对于一个给定字符串(例如, “漫游者”),这两种方法可以返回不同的狗对象。
我应该用@Cacheable(cacheName = "dogs")
对它们进行注释,还是应该将它们放在两个不同的缓存中:“bestDogs”和“bestBrownDogs”?
例2:
我有以下几种方法:
public Dog getBestDogByName(String name) {
//Find the best dog with the provided name
}
public Dog getBestDogByColour(String colour) {
//Find the best dog with the provided colour
}
名称 “漫游者” 和色彩 “狗色” 可以返回相同的狗。
我是否应该用@Cacheable(cacheName = "dogs")
对它们进行注释,还是应该将它们放在两个不同的缓存中:'dogsByName'和'dogsByColour'?
这是否会做任何事情,聪明的一样,如果它是由不同的两种方法返回存储的对象只有一个副本钥匙? – 2012-02-13 17:09:30
它不会,除非有办法在ehcache中配置它。 – aweigold 2012-02-13 17:26:59