第五章 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();


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM