Configure the ehcache address:
Http://code.google.com/p/ehcache-spring-annotations/wiki/UsingTriggersRemove
Hi:
Hello everyone, I am currently using spring ehcache as the project cache. The detailed configuration is as follows:
Ehcaceh_config.xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Beans default-autowire = "byname"
Xmlns = "http://www.springframework.org/schema/beans"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xmlns: AOP = "http://www.springframework.org/schema/aop"
Xmlns: Tx = "http://www.springframework.org/schema/tx"
Xmlns: ehcache = "http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
Xmlns: context = "http://www.springframework.org/schema/context"
Xsi: schemalocation ="
Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
Http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
Http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd>
<Ehcache: annotation-driven cache-Manager = "ehcachemanager"/>
<Bean id = "ehcachemanager" class = "org. springframework. cache. ehcache. ehcachemanagerfactorybean">
<Property name = "configlocation" value = "/WEB-INF/classes/ehcache. xml"> </property>
</Bean>
</Beans>
Ehcache. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Ehcache xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: nonamespaceschemalocation = "http://ehcache.org/ehcache.xsd" updatecheck = "false">
<Diskstore Path = "Java. Io. tmpdir/ehcachespringannotationsexampleapp"/>
<Defaultcache
Maxelementsinmemory = "100"
Eternal = "false"
Timetoidleseconds = "3000"
Timetoliveseconds = "3000"
Overflowtodisk = "true"
Diskspoolbuffersizemb = "30"
Maxelementsondisk= "100"
Diskpersistent = "false"
Diskexpirythreadintervalseconds = "100"
Memorystoreevictionpolicy = "LRU"
Statistics = "false"
/>
<Cache name = "usercache"
Maxelementsinmemory = "100"
Maxelementsondisk= "100"
Eternal = "false"
Overflowtodisk = "true"
Diskspoolbuffersizemb = "20"
Timetoidleseconds = "100"
Timetoliveseconds = "100"
Memorystoreevictionpolicy = "LFU"
Transactionalmode = "off"
/>
</Ehcache>
@ Cacheable (cachename = "usercache ")
Public concurrentmap <integer, usermodel> getalluserinfomap (){
List <usermodel> List = (list <usermodel>) getsqlmapclienttemplate ()
. Queryforlist ("user. select_user_all_info ");
Concurrentmap <string, usermodel> usermap = NULL;
If (collectionutils. isnotempty (list )){
Usermap = new concurrenthashmap <string, usermodel> ();
For (usermodel: List ){
Usermap. Put (usermodel. GETID (), usermodel );
}
}
Return usermap;
}
@ Triggersremove (cachename = "usercache", removeall = true)
Public void insertuser (usermodel ){
Getsqlmapclienttemplate (). insert ("user. insert_user_pojo", usermodel );
}
Note the cache density.
I suggest you use the following method.
@ Cacheable (cachename = "cachename", keygenerator = @ keygenerator (
Name = "hashcodecachekeygenerator ",
Properties = @ property (name = "includemethod", value = "false ")
)
)
If you are interested, you can check that the cache of ehcache source is controlled by hashcode.
For more information, see actcachekeygenerator ,,
{Code}
Public final t generatekey (methodinvocation ){
Final object [] arguments = methodinvocation. getarguments ();
If (this. includemethod ){
Final method = methodinvocation. getmethod ();
Final class <?> Declaringclass = method. getdeclaringclass ();
Final string name = method. getname ();
Final class <?> Returntype = method. getreturntype ();
If (this. includeparametertypes ){
Final class <?> [] Parametertypes = method. getparametertypes ();
Return this. generatekey (declaringclass, name, returntype, parametertypes, arguments );
}
Return this. generatekey (declaringclass, name, returntype, arguments );
}
Try {
Return this. generatekey (arguments );
}
Finally {
If (this. checkforcycles ){
// Cleanup our Thread Local Data
Registry. Remove ();
}
}
}
{Code}