Datastore Introduction
1Gateway Groovy data stores are either held in memory or backed by a MongoDB collection. There are two global datastores bound to any Groovy script by default: db and memory. DB type data stores can hold messages and text values. Memory stores can hold any variable.
To get a private (meaning private binding, the data can still be accessed by any plugin) memory datastore use:
mem = option.memorystore(“MemoryStoreName”)
and for a private (meaning private binding, the data can still be accessed by any plugin) database store use:
mydb = option.dbstore(“DatabaseName”)
You can then use the variables (mem and mydb in the examples above) instead of memory and db.
Use tertiaries to make initialising a variable easier. This will check if the memory count is not null, if it’s not null it will increment the counter, otherwise it will set the counter to 0:
memory.put("counter", memory.counter ? memory.counter+1 : 0)