[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
EHCache + terracotta 做集群分布式缓存问题 求帮助  XML
Forum Index -> Terracotta 中文社区
Author Message
abner

neo

Joined: 09/28/2014 02:18:05
Messages: 3
Offline

hi 各位好 ,如题 在开发中出现了点问题,希望各位帮帮忙 谢谢

好了,废话不多说 上代码以及配置文件。
----------------------------------------------------

ehcache.xml
-------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
monitoring="off">
<terracottaConfig url="localhost:9510"></terracottaConfig>
<cacheManagerEventListenerFactory
class="" properties="" />
<cache name="com.zznode.ehcache.demo" maxElementsInMemory="10000"
maxElementsOnDisk="1000" eternal="false" overflowToDisk="false"
timeToIdleSeconds="300" timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU">
<terracotta clustered="true" />
</cache>
</ehcache>


java
-------------------
package com.abner.ehcache.cache;


import java.io.InputStream;


import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;


public class MyCacheManager {

private MyCacheManager(){}

private static InputStream is = null;
private static CacheManager cm = null ;

static{
is = MyCacheManager.class.getClassLoader().getResourceAsStream(Constant.EHCACHE_CONFIG_NAME);
cm = CacheManager.create(is);
}

public static CacheManager getInstance(){
return cm;
}




}




//PUT 这里数据是能正常的缓存到内存中的
Cache cache = MyCacheManager.getInstance().getCache("simpleCache");
Element ele = new Element(“cacheData”,data) ;
cache.put(ele);


//GET 这里在一段时间后就取不到数据了
Element ele = MyCacheManager.getCache("simpleCache").get("cacheData");








terracotta tc-config.xml
-------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<tc:tc-config xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-4.xsd"
xmlns:tc="http://www.terracotta.org/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


<servers>
<server host="localhost">
<dso-port>9510</dso-port>
</server>
<update-check>
<enabled>true</enabled>
</update-check>
</servers>
<clients>
<modules>
<module name="tim-tomcat-6.0" version="2.3.6"/>
</modules>
</clients>
<application>
<dso>
<instrumented-classes>
<include>
<class-expression>com.loveemps.web.bean.*</class-expression>
</include>
</instrumented-classes>

<web-applications>
<web-application>jsp-examples</web-application>
</web-applications>
</dso>
</application>
</tc:tc-config>




在 ehcache.xml 中的 cache 中配置了 <terracotta clustered="true" /> 就会导致 put 数据后,过56秒左右的时间,缓存中的数据就会被清空。删掉这行配置就没问题~~ 很奇怪
abner

neo

Joined: 09/28/2014 02:18:05
Messages: 3
Offline

大家好,问题已解决。

ehcache.xml
-----------------------------
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
monitoring="off">
<terracottaConfig url="localhost:9510"></terracottaConfig>
<cacheManagerEventListenerFactory
class="" properties="" />
<defaultCache maxElementsInMemory="100000" eternal="false" memoryStoreEvictionPolicy="LRU"
timeToIdleSeconds="100000" timeToLiveSeconds="100000" maxElementsOnDisk="0">
<terracotta clustered="true" coherent="true" valueMode="serialization"/>
</defaultCache>


<cache name="com.abner.ehcache.demo" maxElementsInMemory="10000"
maxElementsOnDisk="1000" eternal="true"
timeToIdleSeconds="300" timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU">
<terracotta clustered="true" coherent="true" valueMode="serialization"/>
</cache>
</ehcache>

-----------------------


修改了一下配置文件,具体为什么现在又没问题了。还是没搞清楚原理。
发现在使用的过程中,有时候会导致 terracotta 服务器断开,也许这也是
导致缓存清空的原因吧
 
Forum Index -> Terracotta 中文社区
Go to:   
Powered by JForum 2.1.7 © JForum Team