Skip to content

Commit

Permalink
Insert the latest version returned in GetAndFetchLatest into the cache
Browse files Browse the repository at this point in the history
  • Loading branch information
anaisbetts committed Dec 30, 2011
1 parent c634f6c commit 7ea4467
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Akavache/BlobCacheExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public static IObservable<T> GetOrFetchObject<T>(this IBlobCache This, string ke
public static IObservable<T> GetAndFetchLatest<T>(this IBlobCache This, string key, Func<IObservable<T>> fetchFunc, DateTimeOffset? absoluteExpiration = null)
{
var fail = Observable.Defer(() => fetchFunc())
.Finally(() => This.Invalidate(key));
.Finally(() => This.Invalidate(key))
.Do(x => This.InsertObject(key, x, absoluteExpiration));

var result = This.GetObjectAsync<T>(key).Select(x => new Tuple<T, bool>(x, true))
.Catch(Observable.Return(new Tuple<T, bool>(default(T), false)));
Expand All @@ -124,7 +125,7 @@ public static IObservable<T> GetAndFetchLatest<T>(this IBlobCache This, string k
return x.Item2 ?
Observable.Return(x.Item1) :
Observable.Empty<T>();
}).Concat(fail);
}).Concat(fail).Multicast(new AsyncSubject<T>()).RefCount();
}

static string GetTypePrefixedKey(string key, Type type)
Expand Down

0 comments on commit 7ea4467

Please sign in to comment.