[Opensymphony-oscache] Problems caching objects
Diego Manilla Suárez <[email protected]> Fri, 22 Jul 2005 11:21:41 +0200
| Newsgroups | gmane.comp.java.open-symphony.os-cache |
|---|---|
| Message-ID | <[email protected]> |
Hi. I have an object, which is a bean with nested beans, but I can't
cache it using OSCache. Here you have a code snippet.
Cache cache = sca.getCache(request, PageContext.APPLICATION_SCOPE);
String key = sca.generateEntryKey("mybean", request,
PageContext.APPLICATION_SCOPE);
MyBean bean = null;
try {
bean = (MyBean)cache.getFromCache(key);
} catch (NeedsRefreshException nre) {
cache.cancelUpdate(key);
bean = getBean();
cache.putInCache(key, bean);
//No exception thrown, it seems to be cached just fine
try {
//The object can be serialized and deserialized with no
problems
ObjectOutputStream oos = new ObjectOutputStream(new
FileOutputStream("C:/temp/prueba.out"));
oos.writeObject(categoryForm);
ObjectInputStream ois = new ObjectInputStream(new
FileInputStream("C:/temp/prueba.out"));
MyBean bean2 = (MyBean)ois.readObject();
//Try to get the cached object -> NeedRefreshException
thrown, why???
bean = (MyBean)cache.getFromCache(key);
} catch (Exception e) {
e.printStackTrace();
}
}
If instead of a MyBean object I use another type of object, an
ArrayList, for example, it works just fine. If I use memory caching
only, it works, too. Other than implementing Serializable, is there any
other requirements that an object needs to meet in order to be cached
with HashDiskPersistenceListener?
I'm using OSCache 2.1.1. My oscache.properties looks like this:
cache.memory=false
cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.HashDiskPersistenceListener
cache.path=c:\\temp\\cache
cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache
cache.capacity=1000
Thanks in advance.