Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file manifest load issues #188

Merged
merged 2 commits into from
Aug 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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