我的班级中介代码是:
package wso2.caching;
import org.apache.synapse.MessageContext;
import org.apache.synapse.mediators.AbstractMediator;
import java.util.Date;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import net.sf.ehcache.Cache;
import net.sf.ehcache.config.CacheConfiguration;
public class CacheMe extends AbstractMediator {
String data = "";
CacheManager cacheManager;
CacheConfiguration cacheConfiguration;
Element element;
private Cache mdmCache;
boolean firstTime=true;
public boolean mediate(MessageContext messageContext) {
System.out.println(new Date() + "FirstTime = " + firstTime);
data = String.valueOf(messageContext.getProperty("propertyarray"));
System.out.println("data from proxy service is : " + data);
cacheData(data);
messageContext.setProperty("ResultData", "You got Data");
return true;
}
public void cacheData(String data){
if(firstTime){
cacheManager = new CacheManager();
firstTime=false;
}
System.out.println(new Date() + "FirstTime = " + firstTime);
System.out.println("Checkpoint A");
//mdmCache = new Cache(getCacheConfiguration("mdmCache"));//test
cacheManager.addCache("mdmCache");
System.out.println("Checkpoint B");
this.mdmCache = cacheManager.getCache("mdmCache");
System.out.println("Checkpoint C");
//this.mdmCache = mdmCache;//test
System.out.println(new Date() + " Generating MDM Data...");
System.out.println("mdmCache.size(): " + mdmCache.getSize());
Element eqpElement = new Element("CacheValueKey", data);
mdmCache.put(eqpElement);
System.out.println("mdmCache.size(): " + mdmCache.getSize());
}
}
我在esb的序列中调用此类调解器,最后在代理服务中调用:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="cacheImplementationSeq">
<property xmlns:ns="http://org.apache.synapse/xsd" name="propertyarray" expression="$body"/>
<log level="custom">
<property xmlns:ns="http://org.apache.synapse/xsd" name="PropertyData" expression="get-property('propertyarray')"/>
</log>
<class name="cts.falcon.data.cachable.CacheData"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="ResultSet" expression="get-property('ResultData')" scope="default" type="STRING"/>
<header name="To" action="remove"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<property name="NO_ENTITY_BODY" action="remove" scope="axis2"/>
<payloadFactory>
<format>
<resultSetResponse xmlns:ns1="http://www.cts.falcon.data.cachable/">$1</resultSetResponse>
</format>
<args>
<arg xmlns:ns="http://org.apache.synapse/xsd" expression="get-property('ResultSet')"/>
</args>
</payloadFactory>
<send/>
</sequence>
当我第一次从try-it运行我的代理服务时,我的响应被缓存有一个唯一的密钥(它是一个UUID),当我再次运行我的服务时,我的上一个密钥被一个新密钥和一个新密钥替换响应值。我正在寻找的是,如果我的密钥是相同的,它应该更新缓存,如果我的密钥不同,它应该添加一个新密钥和我以前的缓存密钥不应该消失?我正在使用ehcache1.5.0 jar来实现插件中带有wso2 esb的这个。期待您的回答。提前致谢
答案 0 :(得分:0)
问题出在您的班级调解员.Debug并找到