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触发常见缓存操作的事件:OnGet、OnAdd、OnPut、OnRemove、OnClear、OnClearRegion 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");
}
- GitHub 地址:https://github.com/MichaCo/CacheManager
Finally, if you like my article, please pay attention and like it, hoping that the net ecosystem will get better and better!
