Spring cache (Getting started)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.