Spring hecache总是返回相同的结果
我正在开发一个web服务系统。我正在使用Spring框架和hecache。 问题是,当我对URL执行第一个请求时,我得到了正确的结果,但是当我使用另一个参数执行第二个请求时,它仍然返回与第一个请求相同的结果。当缓存过期时,它第一次返回正确的结果 这是我的春季服务方法Spring hecache总是返回相同的结果,spring,spring-mvc,caching,ehcache,cache-control,Spring,Spring Mvc,Caching,Ehcache,Cache Control,我正在开发一个web服务系统。我正在使用Spring框架和hecache。 问题是,当我对URL执行第一个请求时,我得到了正确的结果,但是当我使用另一个参数执行第二个请求时,它仍然返回与第一个请求相同的结果。当缓存过期时,它第一次返回正确的结果 这是我的春季服务方法 @Cacheable(value="getUserInformation", key="#progid") public Object getUserInformation(String login, String progid,
@Cacheable(value="getUserInformation", key="#progid")
public Object getUserInformation(String login, String progid, HttpServletRequest request){
System.out.println( login.concat(progid) );
try {
SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate).
withCatalogName("siv_pck_general_functions").
withFunctionName("fn_get_user_information");
SqlParameterSource out = new MapSqlParameterSource().addValue("p_loginname", login).addValue("p_programid", progid);
map.put("Result", simpleJdbcCall.executeFunction(List.class, out) );
logger.info( LogUtils.getTypeMessage(request.getRemoteAddr(), request.getRequestURI(), LogUtils.INFO ));
} catch (Exception e) {
map.put("Result","Error");
}
return map;
}
这是我的ecache配置
<cache name="getUserInformation"
maxEntriesLocalHeap="10000"
maxEntriesLocalDisk="1000"
eternal="false"
diskSpoolBufferSizeMB="20"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU"
transactionalMode="off">
<persistence strategy="localTempSwap" />
</cache>
我在这里看到的看起来是正确的-与完整的webservice调用相比,仅测试此代码的结果如何?问题是登录变量是我数据库中的主键。函数返回正确的信息,但当我使用登录值调用可缓存函数时,它会将相应的信息返回到登录id。如果我使用另一个登录id再次调用该函数,它会返回第一次调用返回的信息。我从最初的问题描述中了解到这一点。但是您提到了一个webservice调用,而显示的代码只包含一个缓存注释。所以我假设您有更多的代码来执行WS-binding和exposition。也许问题就出在这段代码里。这让我问,如果单独测试这里提供的服务(但仍然在Spring上下文中),会发生什么情况。
@RequestMapping( value="/getUserInformation/{loginName}/{programId}/{token}", method = RequestMethod.GET, produces="application/json;charset=UTF-8" )
public Object getUserInformation( @PathVariable String loginName, @PathVariable String programId, @PathVariable String token,HttpServletRequest request){
httpServletRequest = request;
String result = validateToken(token);
if ( "OK".equals(result) ){
map.put("Result", service.getUserInformation(loginName, programId, request) );
}else{
map.put("Result",result);
}
return map;
}