----------------------------------------------------------- // Typical use with fail over // --------------------------------------------------------------- String myKey = "myKey"; String myValue; int myRefreshPeriod = 1000; try { // Get from the cache myValue = (String) admin.getFromCache(myKey, myRefreshPeriod); } catch (NeedsRefreshException nre) { try { // Get the value (probably by calling an EJB) myValue = "This is the content retrieved."; // Store in the cache admin.putInCache(myKey, myValue); } catch (Exception ex) { // We have the current content if we want fail-over. myValue = (String) nre.getCacheContent(); // It is essential that cancelUpdate is called if the // cached content is not rebuilt admin.cancelUpdate(myKey); } } // --------------------------------------------------------------- // Typical use without fail over // --------------------------------------------------------------- String myKey = "myKey"; String myValue; int myRefreshPeriod = 1000; try { // Get from the cache myValue = (String) admin.getFromCache(myKey, myRefreshPeriod); } catch (NeedsRefreshException nre) { try { // Get the value (probably by calling an EJB) myValue = "This is the content retrieved."; // Store in the cache admin.putInCache(myKey, myValue); updated = true; } finally { if (!updated) { // It is essential that cancelUpdate is called if the // cached content could not be rebuilt admin.cancelUpdate(myKey); } } } // --------------------------------------------------------------- // ---------------------------------------------------------------
@version $Revision: 254 $
@author
Francois Beauregard
@author
Alain Bergevin