lets say I have two methods in my controller to support both json and xml.
@RequestMapping(value = "/get/response.json", method = RequestMethod.GET)
@Cacheable(JSON_CACHE)
public @ResponseBody JSONResponse getJsonResponse(){
return responseService.getJsonResponse();
}
@RequestMapping(value = "/get/response.xml", method = RequestMethod.GET)
@Cacheable(XML_CACHE)
public @ResponseBody XMLResponse getXmlResponse(){
return responseService.getXmlResponse();
}
And two message converters, marshalling my objects into suitable response.
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jsonConverter"/>
<ref bean="xmlConverter" />
</list>
</property>
</bean>
The problem is that Spring 3.1, even though method is annotated with @Cachable, still invokes marshaller for every call. It caches state of the object before marshalling.
This is not acceptable because performance is crucial here and marshalling is too expensive for me. I expected Spring to cache the final response in such case. Am I doing something wrong here?
To avoid this issue ehcache web caching can be used: http://www.ehcache.org/documentation/user-guide/web-caching
It works by simply adding filter to web.xml and provides caching of HTTP responses.