Why does DataCache.Add() not check the real backend? #1173
Labels
Enhancement
Type - Changes that may affect performance, usability or add new features to existing modules.
Ledger
Module - The ledger is our 'database', this is used to tag changes about how we store information
Question
Used in questions
The
DataCache
class has methods likeAdd
,Delete
,Find
etc.Delete()
,Find
,TryGet
all do the following stepsAdd()
does not check the real backend. Why?neo/neo/IO/Caching/DataCache.cs
Lines 46 to 59 in 4112df2
Add()
throws an exception (see line 51) if we try to add something that already exists in the cache. It is a design choice to not allow overwriting values, that's fine. However, if it does not find it in the cache then it happily adds it to the cache and a call tocommit()
will overwrite the value in the real backend. This is inconsistent behaviour. I think there should be 1 of 2 optionsAdd()
always allows overriding data. This means removing the exception.Add()
never allows overriding data. This means adding logic to check if a value exists in the real backend before adding it to the internal cache and throwing an exception if it exists.Now depending if
TryGet()
orGetAndChange()
is called before anAdd()
it will throw an exception or not.The text was updated successfully, but these errors were encountered: