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)
?