Skip to content

Commit

Permalink
Merge pull request #24 from simonthum/raw
Browse files Browse the repository at this point in the history
Add a raw bytes cache mode
  • Loading branch information
acarteas authored Nov 27, 2018
2 parents b546498 + 5b669a1 commit f85b9b5
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 66 deletions.
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

0 comments on commit f85b9b5

Please sign in to comment.