### FlushRegionTest failure error output Source: https://github.com/acarteas/filecache/blob/master/src/FileCache.UnitTests/README.md Example of the error message and stack trace produced by FileCache.FlushRegionTest when the WSL2 system clock is out of sync with the host Windows system. ```text Failed FlushRegionTest [1 s] Error Message: Expected result2 to be , but found "Value2". Stack Trace: at FluentAssertions.Execution.LateBoundTestFramework.Throw(String message) at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message) at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message) at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc) at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc) at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args) at FluentAssertions.Primitives.ReferenceTypeAssertions`2.BeNull(String because, Object[] becauseArgs) at FC.UnitTests.FileCacheTest.FlushRegionTest() in /mnt/path/to/FileCache/src/FileCache.UnitTests/FileCacheTest.cs:line 266 ``` -------------------------------- ### Basic FileCache Usage Source: https://github.com/acarteas/filecache/blob/master/README.md Demonstrates how to instantiate a FileCache object and perform basic read/write operations using the indexer. ```csharp //basic example FileCache simpleCache = new FileCache(); string foo = "bar"; simpleCache["foo"] = foo; Console.WriteLine("Reading foo from simpleCache: {0}", simpleCache["foo"]); ``` -------------------------------- ### Instantiate Basic Caching Scheme Source: https://github.com/acarteas/filecache/blob/master/README.md Explicitly instantiate a FileCache using the Basic caching scheme, which uses cache keys as filenames. ```csharp FileCache cache = new FileCache(FileCacheManagers.Basic); ``` -------------------------------- ### Run FileCache unit tests with dotnet test Source: https://github.com/acarteas/filecache/blob/master/src/FileCache.UnitTests/README.md Navigate to the test project directory and execute the test suite using the .NET CLI. ```shell cd /path/to/FileCache/src/FileCache.UnitTests dotnet test FileCache.UnitTests.csproj ``` -------------------------------- ### Instantiate Hashed Caching Scheme Source: https://github.com/acarteas/filecache/blob/master/README.md Instantiate a FileCache using the Hashed caching scheme, which uses xxHash to generate valid filenames from cache keys. ```csharp FileCache cache = new FileCache(FileCacheManagers.Hashed); ``` -------------------------------- ### Initialize FileCache with ObjectBinder Source: https://github.com/acarteas/filecache/blob/master/README.md Pass an instance of the custom ObjectBinder into the FileCache constructor to support user-defined classes. ```csharp //example with custom data binder (needed for caching user defined classes) FileCache binderCache = new FileCache(new ObjectBinder()); ``` -------------------------------- ### Cache and Retrieve Custom Objects Source: https://github.com/acarteas/filecache/blob/master/README.md Demonstrates storing and retrieving a custom DTO object using the configured binderCache. ```csharp GenericDTO dto = new GenericDTO() { IntProperty = 5, StringProperty = "foobar" }; binderCache["dto"] = dto; GenericDTO fromCache = binderCache["dto"] as GenericDTO; Console.WriteLine( "Reading DTO from binderCache:\n\tIntProperty:\t{0}\n\tStringProperty:\t{1}", fromCache.IntProperty, fromCache.StringProperty ); ``` -------------------------------- ### Implement ObjectBinder for Custom Serialization Source: https://github.com/acarteas/filecache/blob/master/README.md Create this class in your assembly to enable the serialization of custom objects within the FileCache. ```csharp /// /// You should be able to copy & paste this code into your local project to enable /// caching custom objects. /// public sealed class ObjectBinder : System.Runtime.Serialization.SerializationBinder { public override Type BindToType(string assemblyName, string typeName) { Type typeToDeserialize = null; String currentAssembly = Assembly.GetExecutingAssembly().FullName; // In this case we are always using the current assembly assemblyName = currentAssembly; // Get the type using the typeName and assemblyName typeToDeserialize = Type.GetType(String.Format("{0}, {1}", typeName, assemblyName)); return typeToDeserialize; } } } ``` -------------------------------- ### FileCache Methods and Properties Source: https://github.com/acarteas/filecache/blob/master/README.md The FileCache class provides several methods and properties for managing cache state, regions, and disk usage. ```APIDOC ## FileCache API ### Properties - **DefaultCacheManager** (static FileCacheManagers) - Sets the default cache manager. - **DefaultRegion** (string) - Sets the default region for indexer access. - **DefaultPolicy** (CacheItemPolicy) - Sets the default policy for indexer access. - **AccessTimeout** (TimeSpan) - Sets the duration to wait for file availability. - **MaxCacheSize** (long) - Sets the maximum disk size in bytes. - **CurrentCacheSize** (long) - Returns the approximate current cache size. ### Methods - **GetKeys(string regionName = null)** - Returns a list of keys for a given region. - **GetPolicy(string key, string regionName = null)** - Returns the policy for a specific cache item. - **GetRegions()** - Returns a list of all regions. - **GetCacheSize(string regionName = null)** - Calculates the size in bytes of the cache or a specific region. - **Clear()** - Clears all items from the disk. - **Flush(string regionName = null)** - Flushes the cache using DateTime.Now as the minimum date. - **Flush(DateTime minDate, string regionName = null)** - Flushes the cache based on last access date. ### Events - **MaxCacheSizeReached** - Event triggered when the maximum cache size is reached. ``` -------------------------------- ### FileCache Extended API Reference Source: https://github.com/acarteas/filecache/blob/master/README.md A list of additional methods and properties exposed by FileCache beyond the standard ObjectCache implementation. ```csharp /// /// Allows for the setting of the default cache manager so that it doesn't have to be /// specified on every instance creation. /// public static FileCacheManagers DefaultCacheManager { get; set; } /// /// Used to store the default region when accessing the cache via [] /// calls /// public string DefaultRegion { get; set; } /// /// Used to set the default policy when setting cache values via [] /// calls /// public CacheItemPolicy DefaultPolicy { get; set; } /// /// Used to determine how long the FileCache will wait for a file to /// become available. Default (00:00:00) is indefinite. Should the /// timeout be reached, an exception will be thrown. /// public TimeSpan AccessTimeout { get; set; } /// /// Returns a list of keys for a given region. /// /// /// public string[] GetKeys(string regionName = null) /// /// Returns the policy attached to a given cache item. /// /// The key of the item /// The region in which the key exists /// public CacheItemPolicy GetPolicy(string key, string regionName = null) /// /// Returns a list of regions, including the root region. /// /// public IEnumerable GetRegions() /// /// Used to specify the disk size, in bytes, that can be used by the File Cache. /// Defaults to long.MaxValue /// public long MaxCacheSize { get; set; } /// /// Returns the approximate size of the file cache /// public long CurrentCacheSize { get; private set; } /// /// Event that will be called when is reached. /// public event EventHandler MaxCacheSizeReached = delegate { }; /// /// Calculates the size, in bytes of the file cache /// /// The region to calculate. If NULL, will return total /// size. public long GetCacheSize(string regionName = null); /// /// Clears all FileCache-related items from the disk. Throws an exception if the cache can't be /// deleted. /// public void Clear(); /// /// Flushes the file cache using DateTime.Now as the minimum date /// public void Flush(string regionName = null); /// /// Flushes the cache based on last access date, filtered by optional region /// public void Flush(DateTime minDate, string regionName = null); ``` -------------------------------- ### Set Default Cache Manager Source: https://github.com/acarteas/filecache/blob/master/README.md Configure the global default caching scheme by setting the static DefaultCacheManager property. ```csharp FileCache.DefaultCacheManager = FileCacheManagers.Hashed; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.