- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1k
          Remove ChangeSet from StoreView
          #3739
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2b7040a
              ff69413
              aaedc8b
              f06cf0b
              10790c1
              9610824
              89a1ec1
              66c3f67
              fcd947c
              7ffe985
              911a79e
              5eff62b
              ede8ca9
              46f92c4
              500e242
              0941a85
              f9cb69f
              df37bb6
              1ce2865
              6d5bb90
              ec841a4
              8bc5ae8
              6421d7b
              5f4c2ae
              ecdc2b4
              67f11c8
              c4cd0e2
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -43,7 +43,12 @@ public class Trackable(StorageItem item, TrackState state) | |
| } | ||
|  | ||
| private readonly Dictionary<StorageKey, Trackable> _dictionary = []; | ||
| private readonly HashSet<StorageKey> _changeSet = []; | ||
| private readonly HashSet<StorageKey>? _changeSet; | ||
|  | ||
| /// <summary> | ||
| /// True if DataCache is readOnly | ||
| /// </summary> | ||
| public bool IsReadOnly => _changeSet == null; | ||
|  | ||
| /// <summary> | ||
| /// Reads a specified entry from the cache. If the entry is not in the cache, it will be automatically loaded from the underlying storage. | ||
|  | @@ -72,6 +77,16 @@ public StorageItem this[StorageKey key] | |
| } | ||
| } | ||
|  | ||
| /// <summary> | ||
| /// Data cache constructor | ||
| /// </summary> | ||
| /// <param name="readOnly">True if you don't want to allow writes</param> | ||
| protected DataCache(bool readOnly) | ||
| { | ||
| if (!readOnly) | ||
| _changeSet = []; | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this the same as _changeSet = null; ? cause you have  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
 Line 87 creates an empty set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Starting being null | ||
| } | ||
|  | ||
| /// <summary> | ||
| /// Adds a new entry to the cache. | ||
| /// </summary> | ||
|  | @@ -97,7 +112,7 @@ public void Add(StorageKey key, StorageItem value) | |
| { | ||
| _dictionary[key] = new Trackable(value, TrackState.Added); | ||
| } | ||
| _changeSet.Add(key); | ||
| _changeSet?.Add(key); | ||
| } | ||
| } | ||
|  | ||
|  | @@ -113,6 +128,11 @@ public void Add(StorageKey key, StorageItem value) | |
| /// </summary> | ||
| public virtual void Commit() | ||
| { | ||
| if (_changeSet is null) | ||
| { | ||
| throw new InvalidOperationException("DataCache is read only"); | ||
| } | ||
|  | ||
| lock (_dictionary) | ||
| { | ||
| foreach (var key in _changeSet) | ||
|  | @@ -138,6 +158,24 @@ public virtual void Commit() | |
| } | ||
| } | ||
|  | ||
| /// <summary> | ||
| /// Gets the change set in the cache. | ||
| /// </summary> | ||
| /// <returns>The change set.</returns> | ||
| public IEnumerable<KeyValuePair<StorageKey, Trackable>> GetChangeSet() | ||
| { | ||
| if (_changeSet is null) | ||
| { | ||
| throw new InvalidOperationException("DataCache is read only"); | ||
| } | ||
|  | ||
| lock (_dictionary) | ||
| { | ||
| foreach (var key in _changeSet) | ||
| yield return new(key, _dictionary[key]); | ||
| } | ||
| } | ||
|  | ||
| /// <summary> | ||
| /// Creates a snapshot, which uses this instance as the underlying storage. | ||
| /// </summary> | ||
|  | @@ -170,20 +208,20 @@ public void Delete(StorageKey key) | |
| if (trackable.State == TrackState.Added) | ||
| { | ||
| trackable.State = TrackState.NotFound; | ||
| _changeSet.Remove(key); | ||
| _changeSet?.Remove(key); | ||
| } | ||
| else if (trackable.State != TrackState.NotFound) | ||
| { | ||
| trackable.State = TrackState.Deleted; | ||
| _changeSet.Add(key); | ||
| _changeSet?.Add(key); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| var item = TryGetInternal(key); | ||
| if (item == null) return; | ||
| _dictionary.Add(key, new Trackable(item, TrackState.Deleted)); | ||
| _changeSet.Add(key); | ||
| _changeSet?.Add(key); | ||
| } | ||
| } | ||
| } | ||
|  | @@ -262,19 +300,6 @@ public void Delete(StorageKey key) | |
| yield break; | ||
| } | ||
|  | ||
| /// <summary> | ||
| /// Gets the change set in the cache. | ||
| /// </summary> | ||
| /// <returns>The change set.</returns> | ||
| public IEnumerable<KeyValuePair<StorageKey, Trackable>> GetChangeSet() | ||
| { | ||
| lock (_dictionary) | ||
| { | ||
| foreach (var key in _changeSet) | ||
| yield return new(key, _dictionary[key]); | ||
| } | ||
| } | ||
|  | ||
| /// <summary> | ||
| /// Determines whether the cache contains the specified entry. | ||
| /// </summary> | ||
|  | @@ -337,13 +362,13 @@ public bool Contains(StorageKey key) | |
| else | ||
| { | ||
| trackable.State = TrackState.Added; | ||
| _changeSet.Add(key); | ||
| _changeSet?.Add(key); | ||
| } | ||
| } | ||
| else if (trackable.State == TrackState.None) | ||
| { | ||
| trackable.State = TrackState.Changed; | ||
| _changeSet.Add(key); | ||
| _changeSet?.Add(key); | ||
| } | ||
| } | ||
| else | ||
|  | @@ -359,7 +384,7 @@ public bool Contains(StorageKey key) | |
| trackable = new Trackable(item, TrackState.Changed); | ||
| } | ||
| _dictionary.Add(key, trackable); | ||
| _changeSet.Add(key); | ||
| _changeSet?.Add(key); | ||
| } | ||
| return trackable.Item; | ||
| } | ||
|  | @@ -392,7 +417,7 @@ public StorageItem GetOrAdd(StorageKey key, Func<StorageItem> factory) | |
| else | ||
| { | ||
| trackable.State = TrackState.Added; | ||
| _changeSet.Add(key); | ||
| _changeSet?.Add(key); | ||
| } | ||
| } | ||
| } | ||
|  | @@ -402,7 +427,7 @@ public StorageItem GetOrAdd(StorageKey key, Func<StorageItem> factory) | |
| if (item == null) | ||
| { | ||
| trackable = new Trackable(factory(), TrackState.Added); | ||
| _changeSet.Add(key); | ||
| _changeSet?.Add(key); | ||
| } | ||
| else | ||
| { | ||
|  | ||
Uh oh!
There was an error while loading. Please reload this page.