Hi 

 

I have recently downloaded and intend to use JCache for on applications; I have written a class that extends CacheLoader

This class retrieves data from a database.

 

I then have a simple javaBean with a method (getData()) that obtains data from the cache if the data has been has been cached

before otherwise it obtains data from the DB and then save in cache.

 

The Problem

 

When I execute the jsp that uses the bean I get the data, if I keep refreshing in very short intervals(i.e. every second) the data is found from

the cache, but if I refresh say after 30 seconds I get a null value. The cache indicates that it does have my data cached(cacheAccess.isPresent("Key")). When I debug through the code I can see that the CacheObject is there but it's referent is null.

I have included the code for the getData() method below.

 

public String getData() {

String res = null;

      try {

            CacheAccess cacheAccess = CacheAccessFactory.getInstance().getAccess();

            if (cacheAccess.isPresent(DataLoader.LOADER_NAME)) {

                  res = (String)cacheAccess.get(DataLoader.LOADER_NAME);

 

            } else {

                  Attributes at = new Attributes();

                  at.setTimeToLive(10 * 60 * 1000);   //ten minutes

                  at.setIdleTime(5 * 60 * 1000);      //five minutes

                  at.setLoader(new DataLoader());

                  cacheAccess.put(

                  UsersCacheLoader.LOADER_NAME, at, new UsersCacheLoader().load(null, null));

                  res = (String) cacheAccess.get(DataLoader.LOADER_NAME);

            }

} catch (CacheException ce) {

ce.printStackTrace();

}

return res;

}

 

regards 

Thobela

 

CONFIDENTIALITY CAUTION: If you have received this communication in error, please note that it is intended for the addressee only, is private and confidential and dissemination or copying prohibited. Please notify us immediately by e-mail and return the original message. We cannot assure that the integrity of this communication has been maintained nor that it is free of errors, virus, interception or interference. Thank you

Kindly note, it is The IQ Business Group's policy that any waiver, representation, contract or variation of a contract shall not be binding unless reduced to writing and signed by the duly authorized managers of the Company.