So I’m adding many keys pretty fast into the cache, every key has the following process:
Set(key, original_value)- first set for the key. As I get it, the value gets into set buffer and not added immediately into the cache, waiting for the buffer to fill up. Though it immediately adds the value into my DB storage.
After some time (less than buffer propagation), I call
key := Get(k) // cache miss happens here and the value is read from storage ... updating value... Set(k, update_value) // also updates the value in storage
At this stage, as the key is not yet in hashmaps in the cache, this set operation is not treated as immediate update and just added to the buffer as new value I guess?
Get(key)- at this point it all depends on timings. If the first
original_valuemade its way into the cache already, the function returns stale
original_value(cause updated_value is still in the buffer?). If the first Set did not succeed yet, the correct
updated_valueis returned from the storage, as no key in cache yet.
Shouldn’t we somehow check on 2nd
Set() that we already have pending value in buffers and replace it with new value?