我想缓存基于多个条件的参数的响应。
@Caching(
cacheable = {
@Cacheable(cacheNames ="student_name_", key= "#id", condition = "#id == 1"),
@Cacheable(cacheNames ="student_name_", key= "#id", condition = "#id == 2")
}
)
public Student getStudentByID(String id)
{
try
{
System.out.println("Going to sleep for 5 Secs.. to simulate backend call.");
Thread.sleep(1000*5);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
if(id.equalsIgnoreCase("1")) return new Student(id,"Venkat","V");
else if(id.equalsIgnoreCase("2")) return new Student(id,"Jeshwin","J");
else
return new Student(id,"Sajal" ,"V"+ new java.util.Date());
}
在上面的例子中,id为1和2的Student被缓存,其余的应该以正常的流来获取结果。
请让我知道,你的想法。
已尝试使用这些注解缓存响应...但未按预期工作...
@Caching(
cacheable = {
@Cacheable(cacheNames ="student_name_", key= "#id", condition = "#id == 1"),
@Cacheable(cacheNames ="student_name_", key= "#id", condition = "#id == 2")
}
)
1条答案
按热度按时间flseospp1#
用Spring表达式语言试试这个。只使用下面的表达式,不使用其他的。