Skip to content

Commit 9fe2ba3

Browse files
authored
Fix file manifest null reference exception (#265)
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.
1 parent 3790564 commit 9fe2ba3

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/CacheTower/Providers/FileSystem/FileCacheLayer.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ private async Task TryLoadManifestAsync()
8989
if (File.Exists(ManifestPath))
9090
{
9191
CacheManifest = await DeserializeFileAsync<ConcurrentDictionary<string?, ManifestEntry>>(ManifestPath);
92+
CacheManifest ??= new();
9293
}
9394
else
9495
{
@@ -97,7 +98,7 @@ private async Task TryLoadManifestAsync()
9798
Directory.CreateDirectory(Options.DirectoryPath);
9899
}
99100

100-
CacheManifest = new ConcurrentDictionary<string?, ManifestEntry>();
101+
CacheManifest = new();
101102
await SerializeFileAsync(ManifestPath, CacheManifest);
102103
}
103104
}

src/CacheTower/Providers/FileSystem/FileCacheLayerOptions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ ICacheSerializer Serializer
1313
)
1414
{
1515
/// <summary>
16-
/// The default manifest save interval of 5 minutes.
16+
/// The default manifest save interval of 30 seconds.
1717
/// </summary>
18-
public static readonly TimeSpan DefaultManifestSaveInterval = TimeSpan.FromMinutes(5);
18+
public static readonly TimeSpan DefaultManifestSaveInterval = TimeSpan.FromSeconds(30);
1919

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

0 commit comments

Comments
 (0)