Returns the size of the current bucket in the event cache.
cacheSize (cacheName)
Returns the size of the current bucket in the event cache. The function takes the argument of the name of the event cache variable. It returns a long.
This example obtains the top 3 distinct prices per trading symbol. In order to accomplish this task, the example makes use of the getCache(), cacheSize() and deleteCache() functions.
CREATE SCHEMA TradesSchema ( Id integer, TradeTime date, Venue string, Symbol string, Price float, Shares integer ) ; CREATE INPUT WINDOW QTrades SCHEMA TradesSchema PRIMARY KEY (Id) ; CREATE FLEX flexOp IN QTrades OUT OUTPUT WINDOW QTradesStats SCHEMA TradesSchema PRIMARY KEY(Symbol,Price) BEGIN DECLARE typedef [integer Id;| date TradeTime; string Venue; string Symbol; float Price; integer Shares] QTradesRecType; eventCache(QTrades[Symbol], manual, Price asc) tradesCache; typeof(QTrades) insertIntoCache( typeof(QTrades) qTrades ) { integer counter := 0; typeof (QTrades) rec; long cacheSz := cacheSize(tradesCache); while (counter < cacheSz) { rec := getCache( tradesCache, counter ); if( round(rec.Price,2) = round(qTrades.Price,2) ) { deleteCache(tradesCache, counter); insertCache( tradesCache, qTrades ); return rec; break; } else if( qTrades.Price < rec.Price) { break; } counter++; } if(cacheSz < 3) { insertCache(tradesCache, qTrades); return qTrades; } else { rec := getCache(tradesCache, 0); deleteCache(tradesCache, 0); insertCache(tradesCache, qTrades); return rec; } return null; } END; ON QTrades { keyCache( tradesCache, [Symbol=QTrades.Symbol;|] ); typeof(QTrades) rec := insertIntoCache( QTrades ); if(rec.Id) { if(rec.Id <> QTrades.Id) { output setOpcode(rec, delete); } output setOpcode(QTrades, upsert); } }; END;