Skip to content

Commit

Permalink
Merge pull request #188 from TurnerSoftware/fix-file-manifest-load-is…
Browse files Browse the repository at this point in the history
…sues

Fix file manifest load issues
  • Loading branch information
Turnerj authored Aug 29, 2021
2 parents 6b0d912 + b569ac9 commit d865666
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/CacheTower/Providers/FileSystem/FileCacheLayerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace CacheTower.Providers.FileSystem

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

private ConcurrentDictionary<string?, IManifestEntry>? CacheManifest { get; set; }
private ConcurrentDictionary<string?, TManifest>? CacheManifest { get; set; }
private ConcurrentDictionary<string?, AsyncReaderWriterLock> FileLock { get; }

/// <summary>
Expand Down Expand Up @@ -94,7 +94,7 @@ private async Task TryLoadManifestAsync()
{
if (File.Exists(ManifestPath))
{
CacheManifest = await DeserializeFileAsync<ConcurrentDictionary<string?, IManifestEntry>>(ManifestPath);
CacheManifest = await DeserializeFileAsync<ConcurrentDictionary<string?, TManifest>>(ManifestPath);
}
else
{
Expand All @@ -103,7 +103,7 @@ private async Task TryLoadManifestAsync()
Directory.CreateDirectory(DirectoryPath);
}

CacheManifest = new ConcurrentDictionary<string?, IManifestEntry>();
CacheManifest = new ConcurrentDictionary<string?, TManifest>();
await SerializeFileAsync(ManifestPath, CacheManifest);
}
}
Expand Down
13 changes: 13 additions & 0 deletions tests/CacheTower.Tests/Providers/BaseCacheLayerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ namespace CacheTower.Tests.Providers
{
public abstract class BaseCacheLayerTests : TestBase
{
protected static async Task AssertPersistentGetSetCacheAsync<TCacheLayer>(Func<TCacheLayer> cacheLayerFactory) where TCacheLayer : ICacheLayer, IAsyncDisposable
{
await using (var cacheLayerOne = cacheLayerFactory())
{
var cacheEntry = new CacheEntry<int>(12, TimeSpan.FromDays(1));
await cacheLayerOne.SetAsync("AssertPersistentGetSetCache", cacheEntry);
}

await using var cacheLayerTwo = cacheLayerFactory();
var persistedCacheEntry = await cacheLayerTwo.GetAsync<int>("AssertPersistentGetSetCache");
Assert.AreEqual(12, persistedCacheEntry.Value);
}

protected static async Task AssertGetSetCacheAsync(ICacheLayer cacheLayer)
{
var cacheEntry = new CacheEntry<int>(12, TimeSpan.FromDays(1));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using CacheTower.Providers.FileSystem;
using CacheTower.Providers.FileSystem.Json;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand All @@ -24,6 +19,12 @@ public void Setup()
}
}

[TestMethod]
public async Task PersistentGetSetCache()
{
await AssertPersistentGetSetCacheAsync(() => new JsonFileCacheLayer(DirectoryPath));
}

[TestMethod]
public async Task GetSetCache()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using CacheTower.Providers.FileSystem.Protobuf;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand All @@ -23,6 +19,12 @@ public void Setup()
}
}

[TestMethod]
public async Task PersistentGetSetCache()
{
await AssertPersistentGetSetCacheAsync(() => new ProtobufFileCacheLayer(DirectoryPath));
}

[TestMethod]
public async Task GetSetCache()
{
Expand Down

0 comments on commit d865666

Please sign in to comment.