Spring's caching mechanism is the caching mechanism for method latitude,
This means that we do not pay attention to whether the underlying database is used and how it is accessed;
Therefore, this caching method is applicable both to the DAO layer and to the service layer .
Spring configuration file configuration:
<!--cache configuration--
<!--deprecated cache annotations-
<cache:annotation-driven cache-manager= "CacheManager"/>
<!--Spring's own Java.util.concurrent.ConcurrentHashMap-based cache manager (which is available starting from Spring3.1)-
<bean id= "CacheManager" class= "Org.springframework.cache.support.SimpleCacheManager" >
<property name= "Caches" >
<set>
<bean name= "Mycache" class= "Org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"/>
</set>
</property>
</bean>
The service layer example is as follows:
@Transactional (readOnly = True)
@Cacheable (value = "Mycache")
Public Jsonobject GETWFK (jsonobject params) {
Oneob ob = new Oneob ();
try {
list<map<string,object>> Map = LAWASSISTANTMAPPER.GETWFK ();
Ob.setob (map);
}catch (Exception e) {
E.printstacktrace ();
Ob.setcode (500);
Ob.setmsg ("Server Error!!! ");
return new Jsonobject (Json.encode (ob));
}
Ob.setcode (200);
Ob.setmsg ("OK");
Logger.debug (Json.encode (ob));
return new Jsonobject (Json.encode (ob));
}
Because of the spring-brought cache class, it only takes two steps: 1. Declared in the spring configuration file, 2. Add annotations to the service layer before the method code.
Spring cache (Getting started)