Beispiel #1
0
        public void AddOrReplace(K key, V value, Func <UpdateableCacheEntry <V>, bool> invalidation,
                                 Func <V, CancellationToken, Task <V> > update)
        {
            var cacheEntry = UpdateableCacheEntry.From(value, DateTimeOffset.UtcNow, invalidation, update);

            Cache.AddOrUpdate(key, cacheEntry, (k, e) => UpdateableCacheEntry.From(e, value, _clock.UtcNow));
        }
Beispiel #2
0
 public static UpdateableCacheEntry <V> UpdateWith <V>(this UpdateableCacheEntry <V> entry, V value,
                                                       DateTimeOffset clock)
 {
     return(UpdateableCacheEntry.From(value, entry.AddedAt, clock, entry.Invalidation, entry.Update));
 }
Beispiel #3
0
 public static IObservable <UpdateableCacheEntry <V> > RunUpdate <V>(this UpdateableCacheEntry <V> old, IClock clock)
 {
     return(Observable.FromAsync(c => old.Update(old.Value, c))
            .Select(v => new { Value = v, TimeUpdated = clock.UtcNow })
            .Select(t => old.UpdateWith(t.Value, t.TimeUpdated)));
 }