国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

一個(gè).Net Core開(kāi)源緩存中間件,讓你更加簡(jiǎn)單、方便使用緩存

2023-03-17 08:06 作者:程序員-王堅(jiān)  | 我要投稿

項(xiàng)目簡(jiǎn)介

這是一個(gè)基于.Net Core開(kāi)發(fā)的緩存中間件,它支持各種緩存并提供了很多高級(jí)功能。它的主要目標(biāo)是讓開(kāi)發(fā)人員開(kāi)發(fā)更簡(jiǎn)單、特別是一些復(fù)雜的緩存場(chǎng)景。

項(xiàng)目特色功能

1、統(tǒng)一緩存接口:方便我們隨時(shí)調(diào)整緩存策略;

2、支持多種緩存:可以滿足我們多種業(yè)務(wù)場(chǎng)景;

3、支持多種緩存系列化:BinaryFormatter、Newtonsoft.Json,MessagePack和Protobuf;

4、支持緩存AOP:able, put,evict,可以簡(jiǎn)化我們的代碼量;

5、多實(shí)例支持;

6、支持Diagnostics:方便我們跟蹤定位;

7、針對(duì)Redis支持特殊Provider:比如原子遞增遞減的操作等等;

8、二級(jí)緩存。

技術(shù)架構(gòu)

1、跨平臺(tái):這是基于.Net Core開(kāi)發(fā)的系統(tǒng),可以部署在Docker, Windows, Linux。

2、基于Net 6.0開(kāi)發(fā)。

3、支持緩存類別:本地緩存:InMemory,SQLite;分布式緩存:StackExchange.Redis,csredis,EnyimMemcachedCore。

項(xiàng)目結(jié)構(gòu)

===

使用方法

**配置緩存
**

在Startup.cs,配置緩存

public void ConfigureServices(IServiceCollection services) { ? ?...... ? ?services.AddEasyCaching(option => ? ?{ ? ? ? ?//內(nèi)存緩存:default ? ? ? ?option.UseInMemory("default"); ? ? ? ?//內(nèi)存緩存:cus ? ? ? ?option.UseInMemory("cus"); ? ? ? ?//redis緩存:redis1 ? ? ? ?option.UseRedis(config => ? ? ? ?{ ? ? ? ? ? ?config.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379)); ? ? ? ? ? ?config.DBConfig.SyncTimeout = 10000; ? ? ? ? ? ?config.DBConfig.AsyncTimeout = 10000; ? ? ? ? ? ?config.SerializerName = "mymsgpack"; ? ? ? ?}, "redis1") ? ? ? ?.WithMessagePack("mymsgpack")//with messagepack serialization ? ? ? ?; ? ? ? ?//redis緩存:redis2 ? ? ? ?option.UseRedis(config => ? ? ? ?{ ? ? ? ? ? ?config.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6380)); ? ? ? ?}, "redis2"); ? ? ? ?//sqlite緩存 ? ? ? ?option.UseSQLite(config => ? ? ? ?{ ? ? ? ? ? ?config.DBConfig = new SQLiteDBOptions { FileName = "my.db" }; ? ? ? ?}); ? ? ? ?//memcached 緩存 ? ? ? ?option.UseMemcached(config => ? ? ? ?{ ? ? ? ? ? ?config.DBConfig.AddServer("127.0.0.1", 11211); ? ? ? ?}); ? ? ? ?option.UseMemcached(Configuration); ? ? ? ?//fasterKv緩存 ? ? ? ?option.UseFasterKv(config => ? ? ? ?{ ? ? ? ? ? ?config.SerializerName = "msg"; ? ? ? ?}) ? ? ? ? ? ?.WithMessagePack("msg"); ? ?}); }

**使用方式
**

public class CusController : Controller{ ? ?//緩存 ? ?private readonly IEasyCachingProviderFactory _factory; ? ?public CusController(IEasyCachingProviderFactory factory) ? ?{ ? ? ? ?this._factory = factory; ? ?} ? ?// GET api/cus/inmem?name=Default ? ?[HttpGet] ? ?[Route("inmem")] ? ?public string Get(string name = EasyCachingConstValue.DefaultInMemoryName) ? ?{ ? ? ? ?//根據(jù)name,獲取緩存實(shí)例 ? ? ? ?var provider = _factory.GetCachingProvider(name); ? ? ? ?var val = name.Equals("cus") ? "cus" : "default"; ? ? ? ?var res = provider.Get("demo", () => val, TimeSpan.FromMinutes(1)); ? ? ? ?return $"cached value : {res}"; ? ?} ? ?...... }

ResponseCache緩存

[ResponseCache(Duration = 30, VaryByQueryKeys = new string[] { "page" })]public IActionResult List(int page = 0){return Content(page.ToString()); }

AOP緩存

[EasyCachingAble(Expiration = 10)]string GetCurrentUtcTime(); [EasyCachingPut(CacheKeyPrefix = "Castle")]string PutSomething(string str); [EasyCachingEvict(IsBefore = true)]void DeleteSomething(int id);


一個(gè).Net Core開(kāi)源緩存中間件,讓你更加簡(jiǎn)單、方便使用緩存的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
双鸭山市| 白玉县| 兴城市| 井研县| 海城市| 北辰区| 城固县| 古蔺县| 伊川县| 嘉定区| 玉田县| 湄潭县| 通许县| 洪洞县| 延川县| 竹溪县| 西乌珠穆沁旗| 七台河市| 甘孜县| 仙居县| 木里| 莱芜市| 锡林郭勒盟| 永州市| 调兵山市| 霍山县| 大关县| 大丰市| 威信县| 图们市| 古蔺县| 双柏县| 武乡县| 黎川县| 永德县| 霍州市| 界首市| 石首市| 栾川县| 水城县| 民县|