Last active
December 14, 2015 14:29
-
-
Save ricston-git/5101145 to your computer and use it in GitHub Desktop.
cachescope-ehcache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<spring:bean id="cacheManager" name="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"/> | |
<spring:bean id="cache" name="cache" class="org.springframework.cache.ehcache.EhCacheFactoryBean"> | |
<spring:property name="cacheManager" ref="cacheManager"/> | |
<spring:property name="cacheName" value="dbCache"/> | |
<spring:property name="maxElementsInMemory" value="10000"/> | |
<spring:property name="eternal" value="false"/> | |
<spring:property name="timeToIdle" value="120"/> | |
<spring:property name="timeToLive" value="120"/> | |
<spring:property name="overflowToDisk" value="true"/> | |
<spring:property name="maxElementsOnDisk" value="10000000"/> | |
<spring:property name="diskPersistent" value="false"/> | |
<spring:property name="diskExpiryThreadIntervalSeconds" value="120"/> | |
<spring:property name="memoryStoreEvictionPolicy" value="LRU"/> | |
</spring:bean> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ricston.cache; | |
import java.io.Serializable; | |
import net.sf.ehcache.Ehcache; | |
import net.sf.ehcache.Element; | |
import org.mule.api.store.ObjectStore; | |
import org.mule.api.store.ObjectStoreException; | |
public class EhcacheObjectStore<T extends Serializable> implements ObjectStore<T> { | |
private Ehcache cache; | |
@Override | |
public synchronized boolean contains(Serializable key) throws ObjectStoreException { | |
return cache.isKeyInCache(key); | |
} | |
@Override | |
public synchronized void store(Serializable key, T value) throws ObjectStoreException { | |
Element element = new Element(key, value); | |
cache.put(element); | |
} | |
@SuppressWarnings("unchecked") | |
@Override | |
public synchronized T retrieve(Serializable key) throws ObjectStoreException { | |
Element element = cache.get(key); | |
if (element == null) | |
{ | |
return null; | |
} | |
return (T) element.getValue(); | |
} | |
@Override | |
public synchronized T remove(Serializable key) throws ObjectStoreException { | |
T value = retrieve(key); | |
cache.remove(key); | |
return value; | |
} | |
@Override | |
public boolean isPersistent() { | |
return false; | |
} | |
public Ehcache getCache() { | |
return cache; | |
} | |
public void setCache(Ehcache cache) { | |
this.cache = cache; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ee:object-store-caching-strategy name="cachingStrategy" doc:name="cachingStrategy"> | |
<custom-object-store class="com.ricston.cache.EhcacheObjectStore"> | |
<spring:property name="cache" ref="cache"/> | |
</custom-object-store> | |
</ee:object-store-caching-strategy> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment