An event cache is a special SPLASH data structure for grouping and storing events from an input stream. Events are grouped into buckets. You can run aggregate operations like count, sum, and max over a bucket.
eventCache(Trades) events;You can have as many event caches as you wish per input stream, so you can declare this in the same stream:
eventCache(Trades) moreEvents;
[ Symbol='T'; | Shares=10; Price=22.88; ] [ Symbol='CSCO'; | Shares=50; Price=15.66; ]Each event—whether an insert, update, or delete—is put into the corresponding bucket. For instance, if a delete event carrying this bucket comes into the stream, then there are two events in the bucket for "CSCO":
[ Symbol='CSCO'; | Shares=50; Price=15.66; ]You can change that behavior by declaring the event cache to coalesce events:
eventCache(Trades, coalesce) events;In this case, the bucket for "CSCO" then has no events.
You can compute over buckets through aggregate operations. For instance, if you want to compute the total number of shares in a bucket, write sum(events.Shares). Which bucket gets selected? By default, it's the bucket associated with the current event that came from the input stream. You can change the bucket with the keyCache operation.
eventCache(Trades[Shares]) eventsByShares;Or group the same number of shares and the same symbol:
eventCache(Trades[Symbol, Shares]) eventsBySymbolShares;Or group in one large bucket:
eventCache(Trades[]) eventsAll;You can also order the events in the bucket by field:
eventCache(Trades, Price desc) eventsOrderByPrice;This orders the events by descending order of Price. You can use the nth operation to get the individual elements in that order.
eventCache(Trades[Symbol], 10 events) eventsBySymbol10Events;Or set a maximum age of 20 seconds:
eventCache(Trades[Symbol], 20 seconds) eventsBySymbol20Seconds;Or both:
eventCache(Trades[Symbol], 10 events, 20 seconds) eventsSmall;