Skip to content

Commit c0a378c

Browse files
committed
Updated AutoCache to use IPerformAnyOperation
1 parent 93f8aa6 commit c0a378c

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

Chickensoft.Sync/src/primitives/AutoCache.cs

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public interface IAutoCache : IAutoObject<AutoCache.Binding>
7373

7474
/// <inheritdoc cref="IAutoCache"/>
7575
public sealed class AutoCache : IAutoCache,
76-
IPerform<AutoCache.PopOp>,
76+
IPerformAnyOperation,
7777
IPerform<AutoCache.ClearOp>
7878
{
7979
// Atomic operations
@@ -165,8 +165,6 @@ public Binding OnClear(Action callback)
165165
}
166166

167167
private readonly SyncSubject _subject;
168-
private readonly Passthrough _passthrough;
169-
private readonly BoxlessQueue _boxlessQueue;
170168
private readonly Dictionary<Type, object> _comparerDict;
171169
private readonly Dictionary<Type, CachedValue> _valueDict;
172170
private readonly Dictionary<Type, object> _refDict;
@@ -183,8 +181,6 @@ public Binding OnClear(Action callback)
183181
public AutoCache()
184182
{
185183
_subject = new SyncSubject(this);
186-
_passthrough = new Passthrough(this);
187-
_boxlessQueue = new BoxlessQueue();
188184
_comparerDict = [];
189185
_valueDict = [];
190186
_refDict = [];
@@ -284,8 +280,7 @@ public void Update<T>(in T value) where T : struct
284280
_cacheCount++;
285281
}
286282

287-
_boxlessQueue.Enqueue(value);
288-
_subject.Perform(new PopOp());
283+
_subject.Perform(value);
289284
}
290285

291286
/// <summary>
@@ -320,15 +315,16 @@ public void Update<T>(T value) where T : class
320315
}
321316

322317
_refDict[typeof(T)] = value;
323-
_boxlessQueue.Enqueue(new RefValue(value));
324-
_subject.Perform(new PopOp());
318+
_subject.Perform(new RefValue(value));
325319
}
326320

327-
private void Handle<T>(in T value) where T : struct =>
328-
_subject.Broadcast(value); // invoke callbacks registered for this value
329-
330-
void IPerform<PopOp>.Perform(in PopOp op) =>
331-
_boxlessQueue.Dequeue(_passthrough);
321+
void IPerformAnyOperation.Perform<TOp>(in TOp op) where TOp : struct
322+
{
323+
if (op is not ClearOp)
324+
{
325+
_subject.Broadcast(op);
326+
}
327+
}
332328

333329
void IPerform<ClearOp>.Perform(in ClearOp op)
334330
{
@@ -356,17 +352,4 @@ void IPerform<ClearOp>.Perform(in ClearOp op)
356352
/// Clears the cache of any stored values.
357353
/// </summary>
358354
public void Clear() => _subject.Perform(new ClearOp());
359-
360-
private readonly struct Passthrough : IBoxlessValueHandler
361-
{
362-
public readonly AutoCache Cache { get; }
363-
364-
public Passthrough(AutoCache cache)
365-
{
366-
Cache = cache;
367-
}
368-
369-
public void HandleValue<TValue>(in TValue value) where TValue : struct =>
370-
Cache.Handle(value);
371-
}
372355
}

0 commit comments

Comments
 (0)