Skip to content

Commit

Permalink
Fix file manifest null reference exception (#265)
Browse files Browse the repository at this point in the history
The cache manifest can deserialize as `null` under certain circumstances. In those cases, we need to initialise the cache manifest as if this is a fresh file.
  • Loading branch information
Turnerj authored Sep 21, 2023
1 parent 3790564 commit 9fe2ba3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/CacheTower/Providers/FileSystem/FileCacheLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private async Task TryLoadManifestAsync()
if (File.Exists(ManifestPath))
{
CacheManifest = await DeserializeFileAsync<ConcurrentDictionary<string?, ManifestEntry>>(ManifestPath);
CacheManifest ??= new();
}
else
{
Expand All @@ -97,7 +98,7 @@ private async Task TryLoadManifestAsync()
Directory.CreateDirectory(Options.DirectoryPath);
}

CacheManifest = new ConcurrentDictionary<string?, ManifestEntry>();
CacheManifest = new();
await SerializeFileAsync(ManifestPath, CacheManifest);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/CacheTower/Providers/FileSystem/FileCacheLayerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ ICacheSerializer Serializer
)
{
/// <summary>
/// The default manifest save interval of 5 minutes.
/// The default manifest save interval of 30 seconds.
/// </summary>
public static readonly TimeSpan DefaultManifestSaveInterval = TimeSpan.FromMinutes(5);
public static readonly TimeSpan DefaultManifestSaveInterval = TimeSpan.FromSeconds(30);

/// <summary>
/// The time interval controlling how often the cache manifest is saved to disk.
Expand Down

0 comments on commit 9fe2ba3

Please sign in to comment.