Spring-boot using Ehcache Configuration

Source: Internet
Author: User

1. Configuration class

@Configuration @enablecaching Public classcacheconfiguration {//implements Cachingconfigurer {@Bean//@Override     PublicCacheManager CacheManager () {Ehcachecachemanager CacheManager=NewEhcachecachemanager ();        Cachemanager.setcachemanager (Ehcachemanagerfactorybean (). GetObject ()); returnCacheManager; } @Bean//@Override     Publickeygenerator Keygenerator () {return NewSimplekeygenerator (); } @Bean PublicEhcachemanagerfactorybean Ehcachemanagerfactorybean () {Ehcachemanagerfactorybean EhCacheManagerFactoryBean /c10>=NewEhcachemanagerfactorybean (); Ehcachemanagerfactorybean.setconfiglocation (NewClasspathresource ("Ehcache.xml")); Ehcachemanagerfactorybean.setcachemanagername ("Messagecache"); Ehcachemanagerfactorybean.setshared (true); returnEhcachemanagerfactorybean; }//@Override//Public Cacheresolver Cacheresolver () {//        //TODO auto-generated Method Stub//return new Simplecacheresolver ();//    }////@Override//Public Cacheerrorhandler ErrorHandler () {//        //TODO auto-generated Method Stub//return new Simplecacheerrorhandler ();//    }    }

2, the configuration file located in the resource directory Ehcache.xml

<?XML version= "1.0" encoding= "UTF-8"?><Ehcache>    <DefaultcacheEternal= "true"maxelementsinmemory= "+"Overflowtodisk= "false" />    <Cachename= "Messagecache"maxelementsinmemory= "Ten"Eternal= "true"Overflowtodisk= "false" /></Ehcache>

3. Cache Object

    @Cacheable (value= "Messagecache")    public  Integer testcashe (String data) {          Returnnew  Integer (Data.length ());    }

Note: The value parameter of the cache object is consistent with the Ehcache.xml configuration file.

Spring-boot using Ehcache Configuration

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.