-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
QuestionUsed in questionsUsed in questions
Description
I'm looking at
neo/neo/IO/Caching/DataCache.cs
Line 147 in 1e2c6c6
| public TValue GetAndChange(TKey key, Func<TValue> factory = null) |
The name of the function suggests "You get the current item according to a key, and replace that with a new item".
The following is a piece of code where we already found the item in the current cache. The above description matches the if branch but not the else branch of the code below.
neo/neo/IO/Caching/DataCache.cs
Lines 151 to 162 in 1e2c6c6
| if (dictionary.TryGetValue(key, out Trackable trackable)) | |
| { | |
| if (trackable.State == TrackState.Deleted) | |
| { | |
| if (factory == null) throw new KeyNotFoundException(); | |
| trackable.Item = factory(); | |
| trackable.State = TrackState.Changed; | |
| } | |
| else if (trackable.State == TrackState.None) | |
| { | |
| trackable.State = TrackState.Changed; | |
| } |
Why are we not updating trackable.Item with factory() like the function name suggests?
To summarise what the function does
We update trackable.item if:
- the item was found in the cache and its previous state was
DELETED - the item was not found in cache and not in the real DB
We do not update trackable.item if:
- the item was found in the cache, but it's previous state is
CHANGEDorADDED - the item was not found in cache, but found in the DB.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
QuestionUsed in questionsUsed in questions