File tree Expand file tree Collapse file tree
src/CacheTower/Providers/FileSystem
tests/CacheTower.Tests/Providers Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 ) ) ;
Original file line number Diff line number Diff line change 1- using System ;
2- using System . Collections . Generic ;
3- using System . IO ;
4- using System . Linq ;
5- using System . Text ;
1+ using System . IO ;
62using System . Threading . Tasks ;
7- using CacheTower . Providers . FileSystem ;
83using CacheTower . Providers . FileSystem . Json ;
94using 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 {
Original file line number Diff line number Diff line change 1- using System ;
2- using System . Collections . Generic ;
3- using System . IO ;
4- using System . Linq ;
5- using System . Text ;
1+ using System . IO ;
62using System . Threading . Tasks ;
73using CacheTower . Providers . FileSystem . Protobuf ;
84using 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 {
You can’t perform that action at this time.
0 commit comments