Cache_MemoryCache_1简介

1.ASP.NET GitHub地址:https://github.com/aspnet

2.ASP.NET Core缓存 MemoryCache 和 Redis

1.MemoryCache简介

  内存缓存。

  区别:缓存HttpRuntime.Cache 位于System.Web命名空间下。 但是在 ASP.NET Core中System.Web已经不存在。

2.MemoryCacheManager

  

  public class MemoryCacheManager:ICacheManager
  {
    public void Set(string key,object value,TimeSpan cacheTime){
      MemoryCache.Default.Add(key,value,new CacheItemPolicy{SlidingExpireation=cacheTime});
    }
    public T Get<T>(string key){
      return (T)MemoryCache.Default.Get(key);
    }
    public bool Contains(string key){
      return MemoryCache.Default.Contains(key);
    }
    public void Remove(string key){
      MemoryCache.Default.Remove(key);
    }
    public void Clear(){
      foreach(var item in MemoryCache.Default){
      this.Remove(item.Key);
    }
  }

2..为了减少磁盘的读取次数,提高程序性能,将频繁读取的配置文件缓存到内存中,加速配置的读取。并且,在磁盘的配置文件更改后,更新缓存。

猜你喜欢

转载自www.cnblogs.com/sujingnuli/p/9052425.html