Append an item to the cache. Evicts oldest if full. Tracks new updates per symbol for the newUpdates mechanism.
(Object item)
| 54 | * Tracks new updates per symbol for the newUpdates mechanism. |
| 55 | */ |
| 56 | @SuppressWarnings("unchecked") |
| 57 | public synchronized void append(Object item) { |
| 58 | if (this.size() >= this.maxSize) { |
| 59 | this.remove(0); |
| 60 | } |
| 61 | this.add(item); |
| 62 | this.newUpdates.incrementAndGet(); |
| 63 | |
| 64 | // Track per-symbol if item has a symbol field |
| 65 | if (item instanceof Map) { |
| 66 | Object symbol = ((Map<String, Object>) item).get("symbol"); |
| 67 | if (symbol instanceof String s) { |
| 68 | this.newUpdatesBySymbol.merge(s, 1, Integer::sum); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Get the number of new updates (since last call) for a symbol. |