Spring cache

1.  Java method

@Cacheable(“allItems”)
    public List<BaseItems> getAllItems(){      
        refreshAllItems();
        return allItems;
    }

2.  ehcache.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<ehcache xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
 xsi:noNamespaceSchemaLocation=”http://ehcache.org/ehcache.xsd&#8221;
 updateCheck=”false”>
            
    <diskStore path=”java.io.tmpdir” />  
       
    <defaultCache eternal=”false”
       maxElementsInMemory=”700000″
       overflowToDisk=”false”
       diskPersistent=”false”
       timeToIdleSeconds=”86400″
       timeToLiveSeconds=”86400″
       memoryStoreEvictionPolicy=”LRU” />
    
    <cache name=”allItems”
       eternal=”false”
       maxElementsInMemory=”700000″
       overflowToDisk=”false”
       diskPersistent=”false”
       timeToIdleSeconds=”86400″
       timeToLiveSeconds=”86400″
       memoryStoreEvictionPolicy=”LRU” />
</ehcache>

3. spring.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<beans xmlns=”http://www.springframework.org/schema/beans&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
       xmlns:aop=”http://www.springframework.org/schema/aop&#8221;
       xmlns:context=”http://www.springframework.org/schema/context&#8221;
       xmlns:tx=”http://www.springframework.org/schema/tx&#8221;
       xmlns:cache=”http://www.springframework.org/schema/cache&#8221;
       xmlns:p=”http://www.springframework.org/schema/p&#8221;
       xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
            http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd&#8221; >
            
    <!– Enable @AspectJ support –>
    <aop:aspectj-autoproxy/>

    <!– Activates scanning of @Autowired –>
    <context:annotation-config/>
 
    
    <bean id=”cacheManager” p:cache-manager-ref=”ehcache”/>
    <bean id=”ehcache”
                p:config-location=”classpath:ehcache.xml”/>

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s