@cacheable does not work in Spring Ehcache.

Source: Internet
Author: User

Verify that the configuration is not a problem.

The first configuration about Ehcache was placed in the Springmvc.xml, moved to Applicationcontext.xml , resolved.

The following are the configurations for Ehcache:

<!--enable note-Driven caching--
<cache:annotation-driven/>
<!--claims cache Manager--
<bean id= "Cachemanagerfactory" class= "Org.springframework.cache.ehcache.EhCacheManagerFactoryBean" >
<property name= "configlocation" value= "Classpath:meta-inf/cache.xml"/>
</bean>
<bean id= "CacheManager" class= "Org.springframework.cache.ehcache.EhCacheCacheManager" >
<property name= "CacheManager" ref= "Cachemanagerfactory"/>
</bean>


The following are cache.xml:

<?xml version= "1.0" encoding= "UTF8"?>
<ehcache>
<!--writes cached objects to the disk cache when the number of objects in the memory cache exceeds Maxelementsinmemory (requires an object to implement the serialization interface)--
<diskstore path= "E:/ideaprojects/myssh/src/main/resources/cn/cache"/><!--used to configure the physical path used by the disk cache, The Ehcache disk cache uses the file suffix name *.data and *.index--
<defaultcache
maxelementsinmemory= "1000"
Eternal= "false"
Timetoidleseconds= "120"
Timetoliveseconds= "120"
Overflowtodisk= "false"/>
<!--Maxelementsondisk The maximum number of elements that can be stored in the disk cache, 0 means infinity

Maxelementsinmemory the maximum number of elements that can be stored in the memory cache, if the element placed in the cache exceeds this value, there are two cases
1) If overflowtodisk=true, the extra elements in the cache will be placed in the disk file
2) If overflowtodisk=false, replace the elements in the cache based on the Memorystoreevictionpolicy strategy--

<!--whether the object in the eternal cache is permanently valid, that is, if the memory is permanent, timetoidleseconds and timetoliveseconds are ignored when true
Timetoidleseconds the allowable idle time (in seconds) of the cached data before it expires, only when Eternal=false is used, the default value is 0, which means that idle time is infinite, which is an optional property
Timetoliveseconds the cache data is allowed to survive before it expires (in seconds), only when Eternal=false is used, and the default value is 0, which indicates the time to live infinity
Overflowtodisk If the disk cache is enabled when there is not enough memory (that is, Ehcache writes the object to disk when the number of objects in memory reaches Maxelementsinmemory)-


<cache name= "Mycache"
maxelementsondisk= "20000"
Maxelementsinmemory= "2000"
Eternal= "true"
Overflowtodisk= "true"
Diskpersistent= "true"/>

<!--diskpersistent whether to persist the disk cache, when the value of this property is true, the system will find the file named cache name in the disk when initializing, file with suffix named index
This file contains the index of the cache that has been persisted on disk, and the cache is loaded into memory when found
To actually persist the Cache to disk, note that the flush () method is called after you write the program Net.sf.ehcache.xml.Cache.put (element Element)
Diskexpirythreadintervalseconds disk cache cleanup thread run interval, default is 120 seconds
DISKSPOOLBUFFERSIZEMB set buffer size for Diskstore (disk cache), default is 30MB
memorystoreevictionpolicy======== memory storage and deallocation policy, that is, when the maxelementsinmemory limit is reached, Ehcache cleans up the memory based on the specified policy
There are three types of strategies, LRU (least recently used), LFU (most commonly used), FIFO (first-in-one-out), and
</ehcache>

@cacheable does not work in Spring Ehcache.

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.