Forum Discussion
3 years ago
On 1/11/2021 at 8:36 AM, Stuart Weenig said:Yes, you can write JSON content to a cached token since you can write any string object. I'm not sure what the character limit might be.
def scriptCache scriptCache = this.class.classLoader.loadClass("com.santaba.agent.util.script.ScriptCache").getCache(); String token = scriptCache.get("myjson"); if(token == null){ //the token is empty because it has not been set previously //generate the json and set it into a token def json = JsonOutput.toJson([name: 'John Doe', age: 42]) assert json == '{"name":"John Doe","age":42}' scriptCache.set("myjson", json); } else{ //the json has been stored in the cache previously, so let's use it println(token) }
to avoid duplicates i'm writing a script that logs certain events and I want to cache the event ID#. I will probably do something like:
def compare_event_Ids (eventId) { scriptCache = this.class.classLoader.loadClass("com.santaba.agent.util.script.ScriptCache").getCache(); String lastEventId = scriptCache.get("lastEventId"); if(lastEventId == null){ //the id is empty because it has not been set previously //generate the json and set it into a token lastEventId = eventId scriptCache.set("lastEventId", lastEventId); return true } else { //the json has been stored in the cache previously, so let's use it if (lastEventId < eventId) { lastEventId = eventId scriptCash.set("lastEventId", lastEventId); return true } else { return false } }
(more or less pseudo code, just trying to get the concept to work)
do you think that will work?
Related Content
- 10 months ago