我必须缓存以下public
方法的结果:
@Cacheable(value = "tasks", key = "#user.username")
public Set<MyPojo> retrieveCurrentUserTailingTasks(UserInformation user) {
Set<MyPojo> resultSet;
try {
nodeInformationList = taskService.getTaskList(user);
} catch (Exception e) {
throw new ApiException("Error while retrieving tailing tasks", e);
}
return resultSet;
}
我还在这里配置了缓存:
@Configuration
@EnableCaching(mode = AdviceMode.PROXY)
public class CacheConfig {
@Bean
public CacheManager cacheManager() {
final SimpleCacheManager cacheManager = new SimpleCacheManager();
cacheManager.setCaches(Arrays.asList(new ConcurrentMapCache("tasks"),new ConcurrentMapCache("templates")));
return cacheManager;
}
@Bean
public CacheResolver cacheResolver() {
final SimpleCacheResolver cacheResolver = new SimpleCacheResolver(cacheManager());
return cacheResolver;
}
}
我声明如下:
ConcurrentMapCache
(2个实例),它们是
在堆中但空着@CacheConfig(cacheNames = "tasks")
添加在我的上方
控制器Spring版本4.1.3.RELEASE Jdk 1.6
更新001:
@RequestMapping(value = "/{kinematicId}/status/{status}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public DocumentNodeWrapper getDocumentsByKinematicByStatus(@PathVariable String kinematicId, @PathVariable String status, HttpServletRequest request) {
UserInformation user = getUserInformation(request);
Set<ParapheurNodeInformation> nodeInformationList = retrieveCurrentUserTailingTasks(user);
final List<DocumentNodeVO> documentsList = getDocumentsByKinematic(kinematicId, user, nodeInformationList);
List<DocumentNodeVO> onlyWithGivenStatus = filterByStatus(documentsList);
return new DocumentNodeWrapper("filesModel", onlyWithGivenStatus, user, currentkinematic);
}
由于
答案 0 :(得分:5)
调用方法getDocumentsByKinematicByStatus()
与可缓存方法在同一个bean中吗?如果为true,那么这是正常的行为,因为您不是通过代理而是直接调用可缓存的方法。