.net core中使用缓存(cache)
生活随笔
收集整理的這篇文章主要介紹了
.net core中使用缓存(cache)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
官方文檔:https://docs.microsoft.com/en-us/aspnet/core/performance/caching/memory?view=aspnetcore-2.2#use-setsize-size-and-sizelimit-to-limit-cache-size
在類中(不是controller)中使用的時候可以使用這個:
private static MemoryCache cache = new MemoryCache(new MemoryCacheOptions()); //定義cachepublic static object GetCacheValue(string key)//獲取值 {object val = null;if (key != null && cache.TryGetValue(key, out val)){return val; }else{return default(object);}}public static void SetChacheValue(string key, object value)//設置值 {if (key != null){cache.Set(key, value, new MemoryCacheEntryOptions{SlidingExpiration = TimeSpan.FromSeconds(10)});}}?
轉載于:https://www.cnblogs.com/fishyues/p/10278573.html
總結
以上是生活随笔為你收集整理的.net core中使用缓存(cache)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: join 分割数组
- 下一篇: bzoj2146 Construct