Repository navigation
Expand file tree
/
Copy pathIntermediateCache.cs
More file actions
131 lines (114 loc) · 4.08 KB
/
Copy pathIntermediateCache.cs
File metadata and controls
131 lines (114 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.Collections.Generic;
using DynamicData.Kernel;
namespace DynamicData
{
/// <summary>
/// Cache designed to be used for custom operator construction.
/// </summary>
/// <typeparam name="TObject">The type of the object.</typeparam>
/// <typeparam name="TKey">The type of the key.</typeparam>
public sealed class IntermediateCache<TObject, TKey> : IIntermediateCache<TObject, TKey>
{
private readonly ObservableCache<TObject, TKey> _innnerCache;
/// <summary>
/// Initializes a new instance of the <see cref="IntermediateCache{TObject, TKey}"/> class.
/// </summary>
/// <param name="source">The source.</param>
/// <exception cref="System.ArgumentNullException">source</exception>
public IntermediateCache(IObservable<IChangeSet<TObject, TKey>> source)
{
if (source == null) throw new ArgumentNullException("source");
_innnerCache = new ObservableCache<TObject, TKey>(source);
}
/// <summary>
/// Initializes a new instance of the <see cref="IntermediateCache{TObject, TKey}"/> class.
/// </summary>
public IntermediateCache()
{
_innnerCache = new ObservableCache<TObject, TKey>();
}
#region Delegated Members
/// <summary>
/// Action to apply a batch update to a cache. Multiple update methods can be invoked within a single batch operation.
/// These operations are invoked within the cache's lock and is therefore thread safe.
///
/// The result of the action will produce a single changeset
/// </summary>
/// <param name="updateAction">The update action.</param>
public void BatchUpdate(Action<IIntermediateUpdater<TObject, TKey>> updateAction)
{
_innnerCache.UpdateFromIntermediate(updateAction);
}
/// <summary>
/// A count changed observable starting with the current count
/// </summary>
public IObservable<int> CountChanged => _innnerCache.CountChanged;
/// <summary>
/// Returns a filtered changeset of cache changes preceeded with the initial state
/// </summary>
/// <param name="filter">The filter.</param>
/// <returns></returns>
public IObservable<IChangeSet<TObject, TKey>> Connect(Func<TObject, bool> filter)
{
return _innnerCache.Connect(filter);
}
/// <summary>
/// Returns a observable of cache changes preceeded with the initital cache state
/// </summary>
/// <returns></returns>
public IObservable<IChangeSet<TObject, TKey>> Connect()
{
return _innnerCache.Connect();
}
/// <summary>
/// Returns an observable of any changes which match the specified key. The sequence starts with the inital item in the cache (if there is one).
/// </summary>
/// <param name="key">The key.</param>
/// <returns></returns>
public IObservable<Change<TObject, TKey>> Watch(TKey key)
{
return _innnerCache.Watch(key);
}
/// <summary>
/// The total count of cached items
/// </summary>
public int Count => _innnerCache.Count;
/// <summary>
/// Gets the Items
/// </summary>
public IEnumerable<TObject> Items => _innnerCache.Items;
/// <summary>
/// Gets the key value pairs
/// </summary>
public IEnumerable<KeyValuePair<TKey,TObject>> KeyValues => _innnerCache.KeyValues;
/// <summary>
/// Gets the keys
/// </summary>
public IEnumerable<TKey> Keys => _innnerCache.Keys;
/// <summary>
/// Lookup a single item using the specified key.
/// </summary>
/// <remarks>
/// Fast indexed lookup
/// </remarks>
/// <param name="key">The key.</param>
/// <returns></returns>
public Optional<TObject> Lookup(TKey key)
{
return _innnerCache.Lookup(key);
}
internal IChangeSet<TObject, TKey> GetInitialUpdates(Func<TObject, bool> filter = null)
{
return _innnerCache.GetInitialUpdates(filter);
}
/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
public void Dispose()
{
_innnerCache.Dispose();
}
#endregion
}
}