Hello! I have problem with TreeCache. I wrote simpe class to Caching values
based on TreeCache, and it works, but very often
it looses values(there are ie empty Strings as values (no null values!!!)).
Thanks for any help. Here is my cache class:
package utils;
import java.util.*;
import org.jboss.cache.*;
import org.apache.log4j.*;
public class Cache {
static Logger logger = Logger.getLogger(Cache.class);
private static HashMap lastAccesses = new HashMap();
private static int life_time=0;
private static TreeCache jtr = null;
private static void init()
{
if(jtr==null)
{
ResourceBundle data;
String xml_path="";
try
{
data = ResourceBundle.getBundle("Consts");
xml_path=data.getString("cache_xml_path");
life_time=Integer.parseInt(data.getString("cache_life_time"))*1000;
jtr = new TreeCache();
org.jboss.cache.PropertyConfigurator config = new
org.jboss.cache.PropertyConfigurator();
config.configure(jtr, xml_path);
jtr.startService();
}catch(Exception e)
{
logger.debug(e.toString());
}
}
}
public static Object getObject(String object_name)
{
init();
if(lastAccesses.containsKey(object_name))
{
if(new
Date().getTime()-((Date)lastAccesses.get(object_name)).getTime()>=life_time)
return null;
}else
return null;
try
{
if(jtr.exists("/",(Object)object_name))
return (Object)jtr.get("/",(Object)object_name);
else
return null;
}catch(Exception e)
{
logger.debug(e.toString());
}
return null;
}
public static void setObject(String object_name,Object obj)
{
Object oldobj;
init();
try
{
oldobj=jtr.put("/",(Object)object_name,obj);
if(oldobj!=null)
oldobj=null;
oldobj=lastAccesses.put(object_name,(Object)new Date());
if(oldobj!=null)
oldobj=null;
}catch(Exception e)
{
logger.debug(e.toString());
}
}
}
cbroussard@liquiddatainc.com - 01 Dec 2005 17:48 GMT
Have you tried the jboss.org forums. That might be a good place to
post and try to get an answer.
hope that helps,
http://www.binaryfrost.com
Maciej Boniewicz - 02 Dec 2005 07:53 GMT
I think it's very good idea :) Thanks for help :)
> Have you tried the jboss.org forums. That might be a good place to
> post and try to get an answer.
>
> hope that helps,
>
> http://www.binaryfrost.com