Event Caches

Event caches hold a number of previous events for the input stream or streams to a derived stream. They are organized into buckets, based on values of the fields in the records and are often used when vectors or dictionaries are not quite the right data structure.

You can define an event cache in a Local block. A simple event cache declaration:
eventCache(input_stream) e0;
This event cache holds all the events for an input stream "input_stream". The default key structure of the input stream defines the bucket policy. That is, the buckets in this stream correspond to the keys of the input stream.
Suppose the input stream in this case has two fields, a key field k and a data field d. Suppose the events have been:
<input_stream ESP_OPS="i" k="1" d="10"/>
<input_stream ESP_OPS="u" k="1" d="11"/>
<input_stream ESP_OPS="i" k="2" d="21"/>
          
After these events have flowed in, there will be two buckets. The first bucket will contain the first two events, because these have the same key; the second bucket will contain the last event.
Event caches allow for aggregation over events. That is, the ordinary aggregation operations that can be used in aggregate streams can be used in the same way over event caches. The "group" that is selected for aggregation is the one associated with the current event.
<input_stream ESP_OPS="u" k="1" d="12"/>
          
For instance, if the above event appears in this stream, then the expression sum(e0.d) returns 10+11+12=33. You can use any of the accepted aggregation functions, including avg, count, max, and min.