RokLenarcic / memento

Clojure Memoization project
MIT License
33 stars 2 forks source link

Race condition when using secondary index #2

Open RokLenarcic opened 1 year ago

RokLenarcic commented 1 year ago

Problem

The order of operations when loading a value is such:

This opens up a race condition, where if someone is to invalidate by tag ID of the entry after it's been added to cache, but before it's been added to secondary index, the entry will not be removed because it's not present in secondary cache yet.

It is questionable how important is this invalidation miss. It is not possible to know before calculating the value if secondary index will be used.

Approaches

We would need some sort of recent tag invalidations check, which would be consulted to drop cached value as it's loaded.