You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-users@jakarta.apache.org by Tim Cronin <tc...@interwoven.com> on 2005/08/31 21:21:29 UTC
Setting cache timeout on elements
I need to be able to set the cache timeout on individual elements.
I created a simple function to test with:
public void put(Object key, Object value, long ttl)
{
try
{
mCache.put(key, value);
IElementAttributes iea = mCache.getElementAttributes(key);
iea.setMaxLifeSeconds(ttl);
System.out.println(mCache.getElementAttributes(key));
}
catch (CacheException e)
{
throw new RuntimeException("Failed add to cache " + key, e);
}
}
Then I'm testing with the following:
m.put("key", "value", 30);
long time = System.currentTimeMillis();
while (m.get("key") != null)
{
try
{
Thread.sleep(500);
System.err.print(".");
}
catch (InterruptedException e)
{
System.err.println("interupted...");
}
}
System.out.println();
System.out.println(((System.currentTimeMillis() - time)/1000));
But the loop never exits. Am I doing something wrong?