diff --git a/src/FileCache.Signed/FileCache.Signed.csproj b/src/FileCache.Signed/FileCache.Signed.csproj index 97a3cb7..d3f8997 100644 --- a/src/FileCache.Signed/FileCache.Signed.csproj +++ b/src/FileCache.Signed/FileCache.Signed.csproj @@ -1,6 +1,6 @@  - net40;net45;net48;netstandard2.0;netstandard2.1 + net45;net48;netstandard2.0;netstandard2.1 false cache objectcache System.Runtime.Caching.ObjectCache Apache-2.0 @@ -11,8 +11,8 @@ True true true - 0.0.0 - false + 3.1.0 + true True portable @@ -44,9 +44,6 @@ - - - @@ -59,4 +56,57 @@ + + + 2.0.3 + + + 2.0.0 + + + 2.0.0 + + + 2.0.0 + + + + + 2.0.0 + + + 2.0.0 + + + 2.0.0 + + + + + 2.0.3 + + + 2.0.0 + + + 2.0.0 + + + 2.0.0 + + + + + 2.0.3 + + + 2.0.0 + + + 2.0.0 + + + 2.0.0 + + \ No newline at end of file diff --git a/src/FileCache.UnitTests/HashedFileCacheTest.cs b/src/FileCache.UnitTests/HashedFileCacheTest.cs index 69d6a3f..0acd76b 100644 --- a/src/FileCache.UnitTests/HashedFileCacheTest.cs +++ b/src/FileCache.UnitTests/HashedFileCacheTest.cs @@ -357,7 +357,7 @@ public void AccessTimeoutTest() _cache = new FileCache(); _cache.AccessTimeout = new TimeSpan(1); _cache["primer"] = 0; - string filePath = Path.Combine(_cache.CacheDir, "cache", "primer".GetHashCode() + "_0.dat"); + string filePath = Path.Combine(_cache.CacheDir, "cache", HashedFileCacheManager.ComputeHash("primer") + "_0.dat"); FileStream stream = File.Open(filePath, FileMode.Create); try { diff --git a/src/FileCache/FileCache.csproj b/src/FileCache/FileCache.csproj index 7a2cb3a..d1fd45b 100644 --- a/src/FileCache/FileCache.csproj +++ b/src/FileCache/FileCache.csproj @@ -1,6 +1,6 @@  - net40;net45;net48;netstandard2.0;netstandard2.1 + net45;net48;netstandard2.0;netstandard2.1 false cache objectcache System.Runtime.Caching.ObjectCache Apache-2.0 @@ -8,10 +8,10 @@ FileCache is a concrete implementation of the .NET System.Runtime.Caching.ObjectCache that uses the local filesystem as the target location. Copyright (c) 2012, 2013, 2017 Adam Carter (http://adam-carter.com) true - 0.0.0 + 3.1.0 Adam Carter System.Runtime.Caching - false + true True portable @@ -22,6 +22,7 @@ true + true Auto @@ -34,9 +35,6 @@ - - - @@ -49,4 +47,57 @@ + + + 2.0.3 + + + 2.0.0 + + + 2.0.0 + + + 2.0.0 + + + + + 2.0.0 + + + 2.0.0 + + + 2.0.0 + + + + + 2.0.3 + + + 2.0.0 + + + 2.0.0 + + + 2.0.0 + + + + + 2.0.3 + + + 2.0.0 + + + 2.0.0 + + + 2.0.0 + + \ No newline at end of file diff --git a/src/FileCache/HashedFileCacheManager.cs b/src/FileCache/HashedFileCacheManager.cs index 16f1de1..aff7fc8 100644 --- a/src/FileCache/HashedFileCacheManager.cs +++ b/src/FileCache/HashedFileCacheManager.cs @@ -1,18 +1,28 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; - +using System.Data.HashFunction; +using System.Data.HashFunction.xxHash; namespace System.Runtime.Caching { /// - /// File-based caching using the built-in .NET GetHashCode(). Collisions are handled by appending + /// File-based caching using xxHash. Collisions are handled by appending /// numerically ascending identifiers to each hash key (e.g. _1, _2, etc.). /// public class HashedFileCacheManager : FileCacheManager { + private static IxxHash _hasher = xxHashFactory.Instance.Create(); + /// + /// Returns a 64bit hash in hex of supplied key + /// + /// + /// + public static string ComputeHash(string key) + { + var hash = _hasher.ComputeHash(key, 64); + return hash.AsHexString(); + } + /// /// Because hash collisions prevent us from knowing the exact file name of the supplied key, we need to probe through /// all possible fine name combinations. This function is used internally by the Delete and Get functions in this class. @@ -32,7 +42,7 @@ private string GetFileName(string key, string regionName = null) //the policy. It also means that deleting a policy file makes the related .dat "invisible" to FC. string directory = Path.Combine(CacheDir, PolicySubFolder, regionName); - string hash = key.GetHashCode().ToString(); + string hash = ComputeHash(key); int hashCounter = 0; string fileName = Path.Combine(directory, string.Format("{0}_{1}.policy", hash, hashCounter)); bool found = false;