Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Make sure we always create a valid index if the database has old/inva…
Browse files Browse the repository at this point in the history
…lid json data

Fixes #1319
  • Loading branch information
shana committed Feb 1, 2018
1 parent f10ea7d commit ac16e66
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/GitHub.App/Caches/CacheIndex.cs
Expand Up @@ -62,6 +62,7 @@ public CacheIndex Add(string indexKey, CacheItem item)
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);
Expand Down
7 changes: 6 additions & 1 deletion src/GitHub.App/Extensions/AkavacheExtensions.cs
Expand Up @@ -200,7 +200,11 @@ public static class AkavacheExtensions
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
Expand Down Expand Up @@ -264,6 +268,7 @@ public static class AkavacheExtensions
{
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<T, Exception>(Observable.Throw<T>)
.SelectMany(x => x.Save<T>(blobCache, key, absoluteExpiration))
Expand Down

0 comments on commit ac16e66

Please sign in to comment.