Event Caches

Event caches are alternate windowing mechanisms and data structures. They are organized into buckets, with each bucket able to store events or records and each bucket based on values of the fields in the records. Event caches are often used when vectors or dictionaries are not quite the right data structure, such as when a window-type store is needed within a FLEX operator, or as an alternative to the CCL KEEP clause when greater control or flexibility is required.

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 windows define the bucket policy. That is, the buckets in this stream correspond to the keys of the input stream. When the input of an event cache is a window or delta stream, the default bucket policy is set to the primary key of the window or delta stream. When the input of an event cache is an insert-only stream, there is no default bucket policy and a single bucket is created for all the events. However, because streams have no keys, the default behavior is for all the rows in the streams to go into one bucket in the event cache.
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 windows 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 (i.e. the event that has just arrived).
<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.