CacheManager -The open source cache abstraction layer for. NET written in C#

CacheManager -The open source cache abstraction layer for. NET written in C#

CacheManager is an open source cache abstraction layer for. NET written in C#. It supports various cache providers and implements many advanced features

最后更新 7/8/2022 7:03 AM
黑哥聊dotNet
预计阅读 3 分钟
分类
.NET
标签
.NET C# open source

profile

CacheManager 是用 C# 编写的 .NET 的开源缓存抽象层。它支持各种缓存提供程序并实现了许多高级功能。

CacheManager 包的主要目标是让开发人员的生活更容易处理,即使是非常复杂的缓存场景。使用 CacheManager 可以实现多层缓存,例如在分布式缓存前的进程内缓存,只需几行代码。

CacheManager 不仅仅是一个统一各种缓存提供者的编程模型的接口,这将使以后在项目中更改缓存策略变得非常容易。它还提供其他功能,例如缓存同步、并发更新、序列化、事件、性能计数器……开发人员只有在需要时才可以选择加入这些功能。

function list

  • 一种处理不同缓存技术的通用接口:ICache
  • configurable
  • Support for different cache providers
  • Serialization can now be configured. Serialization is required only in distributed caching. If no additional serialization packages are installed and configured, binary serialization will be used
  • Use distributed cached locks or transactions to update values.
  • 记录CacheManager 带有一个可扩展的记录 API
  • Type cache interface.
  • 多层 通过 CacheManager 管理多个缓存句柄,您可以轻松实现分层缓存
  • 缓存区域:即使某些缓存系统不支持或不实现缓存区域,CacheManager 也会实现该机制。例如,这可用于对元素进行分组并一次删除所有元素。
  • Statistics: Counters for various caching operations.
  • 性能计数器:为了能够检查某些数字perfmon``,CacheManager 支持每个管理器实例和每个缓存句柄的性能计数器。
  • 事件系统:CacheManager 触发常见缓存操作的事件:OnGetOnAddOnPutOnRemoveOnClearOnClearRegion
  • System.Web.OutputCache实现使用 CacheManager 作为 OutputCache 提供者,这使得 OutputCache 非常灵活,例如通过在许多 Web 服务器上使用像 Redis 这样的分布式缓存。
  • Cache clients are synchronized using Redis publish/subscribe functions

example

private static void MostSimpleCacheManager()
{
    var config = new ConfigurationBuilder()
        .WithSystemRuntimeCacheHandle()
        .Build();

    var cache = new BaseCacheManager<string>(config);
    // or
    var cache2 = CacheFactory.FromConfiguration<string>(config);
}

private static void EventsExample()
{
    var cache = CacheFactory.Build<string>(s => s.WithDictionaryHandle());
    cache.OnAdd += (sender, args) => Console.WriteLine("Added " + args.Key);
    cache.OnGet += (sender, args) => Console.WriteLine("Got " + args.Key);
    cache.OnRemove += (sender, args) => Console.WriteLine("Removed " + args.Key);

    cache.Add("key", "value");
    var val = cache.Get("key");
    cache.Remove("key");
}

Finally, if you like my article, please pay attention and like it, hoping that the net ecosystem will get better and better!

Keep Exploring

延伸阅读

更多文章
同分类 / 同标签 4/22/2026

Support for. NET by operating system versions (250707 update)

Use virtual machines and test machines to test the support of each version of the operating system for. NET. After installing the operating system, it is passed by measuring the corresponding running time of the installation and being able to run the Stardust Agent.

继续阅读
同分类 / 同标签 2/7/2026

Summary of experience in using AOT

From the very beginning of project creation, you should develop a good habit of conducting AOT release testing in a timely manner whenever new features are added or newer syntax is used.

继续阅读