.net core中使用缓存(cache)
生活随笔
收集整理的這篇文章主要介紹了
.net core中使用缓存(cache)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
官方文檔: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)中使用的時(shí)候可以使用這個(gè):
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)//設(shè)置值 {if (key != null){cache.Set(key, value, new MemoryCacheEntryOptions{SlidingExpiration = TimeSpan.FromSeconds(10)});}}?
轉(zhuǎn)載于:https://www.cnblogs.com/fishyues/p/10278573.html
總結(jié)
以上是生活随笔為你收集整理的.net core中使用缓存(cache)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: join 分割数组
- 下一篇: bzoj2146 Construct