applicationScope is a great way to store data, that is available without constantly reading the values from views or config docs. But from time to time even config data changes and when the values are stored in applicationScope, the changes are not pushed to the application in a reasonable timeframe.
The code snippet lets you update applicationScope variables on an individual schedule.
The sample code update applicationScope.test every 60 seconds.
var test = new de.eknori.Tools();
if (test.refreshCache("test", 60)) {
var currentTime = @Now();
applicationScope.test = currentTime;
return "New value: " + currentTime ;
} else {
return "Cached value: " +applicationScope.test
}
The java code uses import static com.ibm.xsp.extlib.util.ExtLibUtil.getApplicationScope;
So you have to have the extension Library in place. Otherwise you have to write some lines of Java to access the applicationScope w/o the extension Library.
Set private boolean debugMode = false to switch off debugging.