caching - Why Spring message converters still being invoked in @Cachable methods -


lets have 2 methods in controller support both json , 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 2 message converters, marshalling objects 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 spring 3.1, though method annotated @cachable, still invokes marshaller every call. caches state of object before marshalling. not acceptable because performance crucial here , marshalling expensive me. expected spring cache final response in such case. doing wrong here?

to avoid issue ehcache web caching can used: http://www.ehcache.org/documentation/user-guide/web-caching

it works adding filter web.xml , provides caching of http responses.

<filter>     <filter-name>simplecachingheaderspagecachingfilter</filter-name>     <filter-class>net.sf.ehcache.constructs.web.filter.simplecachingheaderspagecachingfilter     </filter-class>     <init-param>         <param-name>suppressstacktrace</param-name>         <param-value>false</param-value>     </init-param>     <init-param>         <param-name>cachename</param-name>         <param-value>cachedpage2cache</param-value>     </init-param> </filter>  <filter-mapping>     <filter-name>simplecachingheaderspagecachingfilter</filter-name>     <url-pattern>/*</url-pattern> </filter-mapping> 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -