Advanced thread-safe generic wrapper for System.Runtime.Caching with comprehensive features including cache groups, dependency management, automatic population, and persistent disk storage. Key Features: • Cache groups for organized data management • Dependency relationships between cache groups • Automatic cache population with custom methods • Persistent cache storage that survives application restarts • Retrieve all items from a group with GetAllByGroup() • Comprehensive metadata and monitoring with GetAllCacheMetadata() • Detailed statistics and disk usage analysis • Multiple expiration strategies (sliding/absolute) • Auto-refresh with configurable intervals • Thread-safe operations with minimal lock contention • JSON-based serialization for persistent storage Perfect for high-performance applications requiring sophisticated caching patterns, data persistence, and comprehensive monitoring capabilities.
$ dotnet add package CacheUtilityThis CacheUtility is a threadsafe and simplified generic System.Runtime.Caching wrapper, supporting easy caching patterns.
Example:
Add the result of calling the function "MyLongRunningTaskAsync" (like a database query) and add it to the cache. The next time this code is called, the result object is retreived from the cache and the function "MyLongRunningTaskAsync" is not invoked.
var result = await CacheUtility.Get("MyKey", "MyGroupName", () =>
{
return MyLongRunningTaskAsync();
});
Remove a key from the cache:
CacheUtility.Remove("MyKey", "MyGroupName");
Remove an entire group (so all the items that have been cached using this group name) from the cache:
CacheUtility.RemoveGroup("MyGroupName");