Solution for caching mandatory data with Redis.
In many cases, requires not just pick up or put the data into the cache. As a rule, data are required.
... check the cache ... if the value is missing, run the calculations ... put value to cache ... Tedious
Solution is quite simple - collapse all of these steps in one operation.
|:: forall ma d . (MonadIO ma, ma ~ Redis, Binary d)|
Prefix for key and tags.
Key in cache. Key will be stored as
|-> Maybe ByteString|
|-> (forall mb. MonadIO mb => mb (d, ByteString, [ByteString], Maybe Integer))|
Computation that returns data, expect value, tags and
All tags will be stored as
|-> ma (Maybe d)|
Stores computation results in Redis. Computation fires only if data absent in cache. Of course, to refresh the data, they must first remove from the cache.
Computation controls everything except prefix and key.
In background data is stored in Redis as HashSet with two fields:
for serialized data and
e for expect field.
Time complexity depends on the situation.
O(1)data exists in cache, expect matches.
O(1)data exists in cache, expect value is
O(2)data exists in cache, but expect value not matches value in cache.
- In all other cases time complexity does not make sense