在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
}
对于给定的字符串(例如“rover”),这两种方法可能会返回不同的Dog对象。
我应该在两个方法上都注释@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
}
名称为"rover"和颜色为"doggy-colour"的狗可能是同一只狗。
我应该在两个不同的缓存中注解它们,'dogsByName'和'dogsByColour',还是都用@Cacheable(cacheName = "dogs")
注解?