I have a dataset in a key value store (similar to Cassandra). The data model is -
Key - ServiceName / timestamp_in_milliseconds value - operation
In the write side I get some operations for a service and I store them as the key value model above. These operations can come at any frequency, once a day, once an hour or few thousands in a minute.
On read path, I get requests where I need to aggregate all the operations from a time range. The key value store allows me to search through the range.
The latency of getting to key value store is quite high and I want to cache the results in a distributed cache (Similar to Redis) to improve performance.
My dilemma is when I get a request for a particular time range, I have no way of knowing whether there was any data for this time range. Since operations do not necessarily have to exist for every datapoint (millisecond timestamp), if an operation is not found in cache it might mean that either we have to fetch it from key-value store or there was no operation for that timestamp. This would make the application to essentially go to the key value store for every request, rendering the cache useless.
Is there any way to design the cache such that I can reliably fetch the values from cache while reloading it at a genuine cache miss (that is when value is present in store but not in cache) ? Also the scale of data is such that I can not store some nil value for every millisecond.