Skip to content

Commit d865666

Browse files
authored
Merge pull request #188 from TurnerSoftware/fix-file-manifest-load-issues
Fix file manifest load issues
2 parents 6b0d912 + b569ac9 commit d865666

4 files changed

Lines changed: 30 additions & 14 deletions

File tree

src/CacheTower/Providers/FileSystem/FileCacheLayerBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace CacheTower.Providers.FileSystem
2727

2828
private HashAlgorithm FileNameHashAlgorithm { get; } = MD5.Create();
2929

30-
private ConcurrentDictionary<string?, IManifestEntry>? CacheManifest { get; set; }
30+
private ConcurrentDictionary<string?, TManifest>? CacheManifest { get; set; }
3131
private ConcurrentDictionary<string?, AsyncReaderWriterLock> FileLock { get; }
3232

3333
/// <summary>
@@ -94,7 +94,7 @@ private async Task TryLoadManifestAsync()
9494
{
9595
if (File.Exists(ManifestPath))
9696
{
97-
CacheManifest = await DeserializeFileAsync<ConcurrentDictionary<string?, IManifestEntry>>(ManifestPath);
97+
CacheManifest = await DeserializeFileAsync<ConcurrentDictionary<string?, TManifest>>(ManifestPath);
9898
}
9999
else
100100
{
@@ -103,7 +103,7 @@ private async Task TryLoadManifestAsync()
103103
Directory.CreateDirectory(DirectoryPath);
104104
}
105105

106-
CacheManifest = new ConcurrentDictionary<string?, IManifestEntry>();
106+
CacheManifest = new ConcurrentDictionary<string?, TManifest>();
107107
await SerializeFileAsync(ManifestPath, CacheManifest);
108108
}
109109
}

tests/CacheTower.Tests/Providers/BaseCacheLayerTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ namespace CacheTower.Tests.Providers
77
{
88
public abstract class BaseCacheLayerTests : TestBase
99
{
10+
protected static async Task AssertPersistentGetSetCacheAsync<TCacheLayer>(Func<TCacheLayer> cacheLayerFactory) where TCacheLayer : ICacheLayer, IAsyncDisposable
11+
{
12+
await using (var cacheLayerOne = cacheLayerFactory())
13+
{
14+
var cacheEntry = new CacheEntry<int>(12, TimeSpan.FromDays(1));
15+
await cacheLayerOne.SetAsync("AssertPersistentGetSetCache", cacheEntry);
16+
}
17+
18+
await using var cacheLayerTwo = cacheLayerFactory();
19+
var persistedCacheEntry = await cacheLayerTwo.GetAsync<int>("AssertPersistentGetSetCache");
20+
Assert.AreEqual(12, persistedCacheEntry.Value);
21+
}
22+
1023
protected static async Task AssertGetSetCacheAsync(ICacheLayer cacheLayer)
1124
{
1225
var cacheEntry = new CacheEntry<int>(12, TimeSpan.FromDays(1));

tests/CacheTower.Tests/Providers/FileSystem/Json/JsonFileCacheLayerTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Text;
1+
using System.IO;
62
using System.Threading.Tasks;
7-
using CacheTower.Providers.FileSystem;
83
using CacheTower.Providers.FileSystem.Json;
94
using Microsoft.VisualStudio.TestTools.UnitTesting;
105

@@ -24,6 +19,12 @@ public void Setup()
2419
}
2520
}
2621

22+
[TestMethod]
23+
public async Task PersistentGetSetCache()
24+
{
25+
await AssertPersistentGetSetCacheAsync(() => new JsonFileCacheLayer(DirectoryPath));
26+
}
27+
2728
[TestMethod]
2829
public async Task GetSetCache()
2930
{

tests/CacheTower.Tests/Providers/FileSystem/Protobuf/ProtobufFileCacheLayerTests.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Text;
1+
using System.IO;
62
using System.Threading.Tasks;
73
using CacheTower.Providers.FileSystem.Protobuf;
84
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -23,6 +19,12 @@ public void Setup()
2319
}
2420
}
2521

22+
[TestMethod]
23+
public async Task PersistentGetSetCache()
24+
{
25+
await AssertPersistentGetSetCacheAsync(() => new ProtobufFileCacheLayer(DirectoryPath));
26+
}
27+
2628
[TestMethod]
2729
public async Task GetSetCache()
2830
{

0 commit comments

Comments
 (0)