第五章 Net 5.0 快速开发框架 YC.Boilerplate -- 缓存模块

在线文档:http://doc.yc-l.com/#/README
在线演示地址:http://yc.yc-l.com/#/login
源码github:https://github.com/linbin524/yc.boilerplate
源码gitee:https://gitee.com/linxuanming/yc.boilerplate
元磁之力框架技术群QQ:1060819005

视频教程:

缓存功能介绍

缓存模块统一继承ICacheManager 接口,目前实现了两种缓存模式,一种是内存缓存,在YC.Core的层中的MemoryCacheManager实现相关代码;另一种是Redis缓存,在Module 目录中独立一个模块:YC.Cache.Redis。

MemoryCache

MemoryCache 实现基础CRUD功能,实现滑动过期,在框架中使用需要在 CustomAutofacModule.cs 注入模块中进行注入操作。

     builder.RegisterType<MemoryCacheManager>().As<ICacheManager>().InstancePerLifetimeScope();

redis Cache

redis 缓存实现基础CRUD功能,框架中使用Redis Session,解决Session 对Cookie 的依赖。

//redis Session 连接
  "ConnectionRedis": {
    "Connection": "127.0.0.1:6379,allowAdmin=true,password=123456,defaultdatabase=0",
    "InstanceName": "Redis",
    "SessionTimeOut": "20"
  },

在框架中使用,需要在 CustomAutofacModule.cs 注入模块中进行如下注入配置操作

            var tempConfigOptions = new StackExchange.Redis.ConfigurationOptions();
            tempConfigOptions.SyncTimeout = 5000;
            tempConfigOptions.ConnectTimeout = 15000;
            tempConfigOptions.ResponseTimeout = 15000;
            //redis cache注入
            builder.RegisterType<RedisCacheManager>().As<ICacheManager>().WithParameter("options", new RedisCacheOptions()
            {
                Configuration = DefaultConfig.ConnectionRedis.Connection,
                InstanceName = DefaultConfig.ConnectionRedis.InstanceName,
                ConfigurationOptions = tempConfigOptions,
            }).InstancePerLifetimeScope();
笔者原创!如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,转载请添加原博客连接,否则保留追究法律责任的权利,谢谢! YC.Boilerplate 快速开发框架交流,请加群:1060819005 区块链交流请加QQ群:538327407(已满),群2:135019400. 我的博客地址:http://www.cnblogs.com/linbin524/
原文地址:https://www.cnblogs.com/linbin524/p/15210257.html