diff --git a/src/GitHub.App/Caches/CacheIndex.cs b/src/GitHub.App/Caches/CacheIndex.cs index a3eca8a0e8..d3ad77de7f 100644 --- a/src/GitHub.App/Caches/CacheIndex.cs +++ b/src/GitHub.App/Caches/CacheIndex.cs @@ -62,6 +62,7 @@ public static IObservable AddAndSaveToIndex(IBlobCache cache, string Guard.ArgumentNotNull(item, nameof(item)); return cache.GetOrCreateObject(indexKey, () => Create(indexKey)) + .Select(x => x.IndexKey == null ? Create(indexKey) : x) .Do(index => { var k = string.Format(CultureInfo.InvariantCulture, "{0}|{1}", index.IndexKey, item.Key); diff --git a/src/GitHub.App/Extensions/AkavacheExtensions.cs b/src/GitHub.App/Extensions/AkavacheExtensions.cs index a95e4c5c8d..bbf59bed19 100644 --- a/src/GitHub.App/Extensions/AkavacheExtensions.cs +++ b/src/GitHub.App/Extensions/AkavacheExtensions.cs @@ -200,7 +200,11 @@ static IObservable GetAndFetchLatestFromIndex(this IBlobCache This, bool shouldInvalidateOnError = false) where T : CacheItem { - var idx = Observable.Defer(() => This.GetOrCreateObject(key, () => CacheIndex.Create(key))).Replay().RefCount(); + var idx = Observable.Defer(() => This + .GetOrCreateObject(key, () => CacheIndex.Create(key))) + .Select(x => x.IndexKey == null ? CacheIndex.Create(key) : x) + .Replay() + .RefCount(); var fetch = idx @@ -264,6 +268,7 @@ public static IObservable PutAndUpdateIndex(this IBlobCache blobCache, { var absoluteExpiration = blobCache.Scheduler.Now + maxCacheDuration; return blobCache.GetOrCreateObject(key, () => CacheIndex.Create(key)) + .Select(x => x.IndexKey == null ? CacheIndex.Create(key) : x) .SelectMany(index => fetchFunc() .Catch(Observable.Throw) .SelectMany(x => x.Save(blobCache, key, absoluteExpiration))