Skip to content

Channel Cache Object

Channel cache is a simple key-value pair database associated with the channel. It can be used to store configuration parameters that change or modify the behavior of the channel. Cache values are persisted and can be referenced across messages. The following Channel Cache object functions are available:

Function Description
Check Value Exists Check for the existence of a value associated with the key. Returns true if a value is found, false otherwise.
Get Boolean Get the Boolean-typed value associated with the key. A ClassCastException is thrown if the cached value is not a Boolean, and a NullPointerException is thrown when no defaultValue is supplied and the key is not present.
Get Date Get the Date-typed value associated with the key. A ClassCastException is thrown if the cached value is not a Date.
Get Number Get the Number-typed value associated with the key. A ClassCastException is thrown if the cached value is not a Number, and a NullPointerException is thrown when no defaultValue is supplied and the key is not present.
Get Value Get the value associated with the key. Accepts an optional defaultValue returned when the key is not present (defaults to null).
Remove Value Remove the channel cache entry that matches the key.
Set Value Set the value associated with the key. Returns the previous value associated with the key.

Note

Channel cache reads and writes are not locked. When messages processed at the same time each read a key, change it, and write it back (for example, incrementing a counter), updates can be lost. A value with a single writer is safe to update from a script, such as a watermark recorded by a scheduled Custom Script Receiver, or a counter in a channel with Process messages in order received turned on. When concurrent messages must update the same key, use the Shared Cache with its mutex around the read and write, or an external database.