|
9 | 9 | // Redistribution and use in source and binary forms with or without
|
10 | 10 | // modifications are permitted.
|
11 | 11 |
|
| 12 | +#nullable enable |
| 13 | + |
12 | 14 | using Neo.SmartContract;
|
13 | 15 | using System.Collections.Generic;
|
14 | 16 |
|
15 | 17 | namespace Neo.Persistence
|
16 | 18 | {
|
17 | 19 | class ClonedCache : DataCache
|
18 | 20 | {
|
19 |
| - private readonly DataCache innerCache; |
| 21 | + private readonly DataCache _innerCache; |
20 | 22 |
|
21 | 23 | public ClonedCache(DataCache innerCache)
|
22 | 24 | {
|
23 |
| - this.innerCache = innerCache; |
| 25 | + _innerCache = innerCache; |
24 | 26 | }
|
25 | 27 |
|
26 | 28 | protected override void AddInternal(StorageKey key, StorageItem value)
|
27 | 29 | {
|
28 |
| - innerCache.Add(key, value.Clone()); |
| 30 | + _innerCache.Add(key, value.Clone()); |
29 | 31 | }
|
30 | 32 |
|
31 | 33 | protected override void DeleteInternal(StorageKey key)
|
32 | 34 | {
|
33 |
| - innerCache.Delete(key); |
| 35 | + _innerCache.Delete(key); |
34 | 36 | }
|
35 | 37 |
|
36 | 38 | protected override bool ContainsInternal(StorageKey key)
|
37 | 39 | {
|
38 |
| - return innerCache.Contains(key); |
| 40 | + return _innerCache.Contains(key); |
39 | 41 | }
|
40 | 42 |
|
41 | 43 | /// <inheritdoc/>
|
42 | 44 | protected override StorageItem GetInternal(StorageKey key)
|
43 | 45 | {
|
44 |
| - return innerCache[key].Clone(); |
| 46 | + return _innerCache[key].Clone(); |
45 | 47 | }
|
46 | 48 |
|
47 | 49 | protected override IEnumerable<(StorageKey, StorageItem)> SeekInternal(byte[] keyOrPreifx, SeekDirection direction)
|
48 | 50 | {
|
49 |
| - foreach (var (key, value) in innerCache.Seek(keyOrPreifx, direction)) |
| 51 | + foreach (var (key, value) in _innerCache.Seek(keyOrPreifx, direction)) |
50 | 52 | yield return (key, value.Clone());
|
51 | 53 | }
|
52 | 54 |
|
53 |
| - protected override StorageItem TryGetInternal(StorageKey key) |
| 55 | + protected override StorageItem? TryGetInternal(StorageKey key) |
54 | 56 | {
|
55 |
| - return innerCache.TryGet(key)?.Clone(); |
| 57 | + return _innerCache.TryGet(key)?.Clone(); |
56 | 58 | }
|
57 | 59 |
|
58 | 60 | protected override void UpdateInternal(StorageKey key, StorageItem value)
|
59 | 61 | {
|
60 |
| - innerCache.GetAndChange(key).FromReplica(value); |
| 62 | + var entry = _innerCache.GetAndChange(key) |
| 63 | + ?? throw new KeyNotFoundException(); |
| 64 | + |
| 65 | + entry.FromReplica(value); |
61 | 66 | }
|
62 | 67 | }
|
63 | 68 | }
|
0 commit comments