Skip to content

Commit

Permalink
Fixed 3 unit tests.
Browse files Browse the repository at this point in the history
Fixed:
  - FileCacheTest.CacheSizeTest
  - FileCacheTest.ShrinkCacheTest
  - HashedFileCacheTest.CacheSizeTest

Moved the calculation of the new policy file's size to be outside the
'using' blocks for writing it to disk so that it could read the actual
file size instead of always getting 0.
  - It is moved entirely out of the using blocks to mirror the cache
    item's code.

Removed a duplicated line of code in FileCache.WriteHelper().
  - There was an `if` line that was there twice.
  - This has no effect on anything other than my sanity.
  • Loading branch information
cole-brown committed Aug 23, 2021
1 parent dc77160 commit 4ba4a8d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/FileCache/FileCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,14 @@ private long CacheSizeHelper(DirectoryInfo root)
{
size += fi.Length;
}

// Add subdirectory sizes.
var dis = root.EnumerateDirectories();
foreach (DirectoryInfo di in dis)
{
size += CacheSizeHelper(di);
}

return size;
}

Expand Down Expand Up @@ -743,10 +745,9 @@ private void WriteHelper(PayloadMode mode, string key, FileCachePayload data, st

//check to see if limit was reached
if (CurrentCacheSize > MaxCacheSize)
if (CurrentCacheSize > MaxCacheSize)
{
MaxCacheSizeReached(this, new FileCacheEventArgs(CurrentCacheSize, MaxCacheSize));
}
{
MaxCacheSizeReached(this, new FileCacheEventArgs(CurrentCacheSize, MaxCacheSize));
}
}

#endregion
Expand Down Expand Up @@ -955,7 +956,6 @@ public override object Remove(string key, string regionName = null)
{
object valueToDelete = null;


if (Contains(key, regionName) == true)
{

Expand Down
6 changes: 3 additions & 3 deletions src/FileCache/FileCacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,12 @@ public virtual long WriteFile(FileCache.PayloadMode mode, string key, FileCacheP
using (BinaryWriter writer = new BinaryWriter(stream))
{
data.Policy.Serialize(writer);

// adjust cache size
cacheSizeDelta += new FileInfo(cachedPolicy).Length;
}
}

// Adjust cache size outside of the using blocks to ensure it's after the data is written.
cacheSizeDelta += new FileInfo(cachedPolicy).Length;

return cacheSizeDelta;
}

Expand Down

0 comments on commit 4ba4a8d

Please sign in to comment.