0

I have a requirement to detect event frequency, e.g. N identical events have occurred within X seconds.

My detection process executes continually 24/7.

My initial design employed a ConcurrentHashMap, The key is a custom value object that represents the Event identity, the value is a Joda DateTime when the event occurred.

This approached worked well for detecting event frequency however I also had to implement an eviction process to remove "Stale" events.

Googling for an improved approach I discovered com.google.common.cache.Cache, which looked promising as its related CacheBuilder has .expireAfter#####(), however all the get methods of Cache are deprecated. Apparently I have to use LoadingCache.

All the examples for LoadingCache load() method show retrieving the value to load by accessing a database or other "Expensive" operation. None of these fit my use case. I have the key and value I need to populate the cache with, how do I "load" my Event on a cache miss when my value doesn't reside in a back end datastore?

Am I supposed to use cache.put(Key, Value)?

Hector
  • 4,016
  • 21
  • 112
  • 211
  • 1
    `Cache#get` isn't deprecated - you can use `get(key, callable)`. You might also find probabilistic data structures, like `CountMinSketch`, useful by perhaps resetting every sample period. – Ben Manes Aug 09 '16 at 07:24
  • @BenManes you are indeed correct. I had an old guava jar file (11) in my build classpath. Thanks for the CountMinSketch {Muthukrishnan/Cormode} tip, that looks very interesting – Hector Aug 09 '16 at 13:59

0 Answers0