Skip to content
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
34 changes: 34 additions & 0 deletions src/FileCache.UnitTests/FileCacheTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ public void CacheSizeTest()
cacheSize.Should().NotBe(0);

_cache.Remove("foo");
cacheSize = _cache.GetCacheSize();
cacheSize.Should().Be(0);
cacheSize = _cache.CurrentCacheSize;
cacheSize.Should().Be(0);
}
Expand Down Expand Up @@ -385,5 +387,37 @@ public void CleanCacheTest()
_cache["foo"].Should().BeNull();
_cache["bar"].Should().NotBeNull();
}

[TestMethod]
public void RawFileCacheTest()
{
// Test with filename based payload
FileCache perfCache = new FileCache("filePayload");
perfCache.PayloadReadMode = FileCache.PayloadMode.Filename;
perfCache.PayloadWriteMode = FileCache.PayloadMode.RawBytes;

perfCache["mybytes"] = new byte[] { 4, 2 };
perfCache.Get("mybytes").Should().BeOfType(typeof(string));
File.Exists((string)perfCache.Get("mybytes")).Should().BeTrue();
}


[TestMethod]
public void RawFileWithExpiryTest()
{
// Test with sliding expiry
FileCache perfCacheWithExpiry = new FileCache("filePayloadExpiry");
var pol = new CacheItemPolicy();
pol.SlidingExpiration = new TimeSpan(0, 0, 2);
perfCacheWithExpiry.DefaultPolicy = pol;
perfCacheWithExpiry.FilenameAsPayloadSafetyMargin = new TimeSpan(0, 0, 1);
perfCacheWithExpiry.PayloadReadMode = FileCache.PayloadMode.Filename;
perfCacheWithExpiry.PayloadWriteMode = FileCache.PayloadMode.RawBytes;

perfCacheWithExpiry["mybytes"] = new byte[] { 4, 2 };
File.Exists((string)perfCacheWithExpiry.Get("mybytes")).Should().BeTrue();
Thread.Sleep(2000);
perfCacheWithExpiry.Get("mybytes").Should().BeNull();
}
}
}
12 changes: 12 additions & 0 deletions src/FileCache.sln
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ Global
{F7C96C00-C7CD-4503-B6BE-B79700D24F68}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{F7C96C00-C7CD-4503-B6BE-B79700D24F68}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{F7C96C00-C7CD-4503-B6BE-B79700D24F68}.Release|x86.ActiveCfg = Release|Any CPU
{3E796953-08A9-4B32-991D-9D7E187BA56D}.Debug|Any CPU.ActiveCfg = Debug|x86
{3E796953-08A9-4B32-991D-9D7E187BA56D}.Debug|Any CPU.Build.0 = Debug|x86
{3E796953-08A9-4B32-991D-9D7E187BA56D}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{3E796953-08A9-4B32-991D-9D7E187BA56D}.Debug|Mixed Platforms.Build.0 = Debug|x86
{3E796953-08A9-4B32-991D-9D7E187BA56D}.Debug|x86.ActiveCfg = Debug|x86
{3E796953-08A9-4B32-991D-9D7E187BA56D}.Debug|x86.Build.0 = Debug|x86
{3E796953-08A9-4B32-991D-9D7E187BA56D}.Release|Any CPU.ActiveCfg = Release|x86
{3E796953-08A9-4B32-991D-9D7E187BA56D}.Release|Any CPU.Build.0 = Release|x86
{3E796953-08A9-4B32-991D-9D7E187BA56D}.Release|Mixed Platforms.ActiveCfg = Release|x86
{3E796953-08A9-4B32-991D-9D7E187BA56D}.Release|Mixed Platforms.Build.0 = Release|x86
{3E796953-08A9-4B32-991D-9D7E187BA56D}.Release|x86.ActiveCfg = Release|x86
{3E796953-08A9-4B32-991D-9D7E187BA56D}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading