要将对象添加到"CplxObj“命名空间,我使用以下方法:
@ReadThroughSingleCache(namespace = "CplxObj", expiration = EXPIRATION_TIME)
public List<MyObj> getComplexObjectFromDB(
@ParameterValueKeyProvider List<MyObj> listToAdd) {
return getSA(listToAdd);
}
/**
* simple-spring-memcached framework will add to cache if element does not exist
* @param listToAdd
* @return
*/
private List<MyObj> getSA(List<MyObj> listToAdd) {
System.out.println("Adding to cache");
return listToAdd;
}但是我怎样才能得到List<MyObj> for an associated key (eg a userId)呢?
public List<MyObj> getComplexObjectFromDB("userId") {
//logic to get the List associated with the key
}我不认为我应该为每个id创建一个新的命名空间?
发布于 2014-05-13 05:16:38
简单Spring (SSM)注释@ReadThroughSingleCache的工作方式如下:
如您所见,@ReadThroughSingleCache将在没有缓存时将值赋值给缓存,并在出现时从缓存中获取值。
由于@ReadThroughSingleCache将整个结果存储在单个缓存键下,所以它通常不与List @ParameterValueKeyProvider一起使用。常见的用法是:
@ReadThroughSingleCache(namespace = "CplxObj", expiration = EXPIRATION_TIME)
public List<User> getUserByNameFromDB(@ParameterValueKeyProvider String name) {
List<User> users = ......; // query DB to find users with given name
return users;
}因此,下次调用getUserByNameFromDB时,将从缓存返回相同的名称,而不是查询数据库结果。
https://stackoverflow.com/questions/23612585
复制相似问题