而且用依賴注入在每個Controller的建購子還要在宣告,覺的有點麻煩
只好先把快取先放入靜態類別來直接使用
先建立一個類別
public static class SystemCache
{
public static IMemoryCache MemoryCache { get; set; }
}
在Startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//...其它略
SystemCache.MemoryCache = app.ApplicationServices.GetRequiredService();
}
使用方式
SystemCache.MemoryCache.Set("test", DateTime.Now.ToString());
var testTime = SystemCache.MemoryCache.Get("test").ToString();
沒有留言:
張貼留言