第五章 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();
posted @ 2021-08-31 14:38  linbin524  阅读(212)  评论(0编辑  收藏  举报