.net 4 中的 MemoryCache 有什么作用?这缓存能不能常驻内存? 想拥有memcached这样的功能

            var cp = new CacheItemPolicy();
            //cp.SlidingExpiration = new TimeSpan(0, 0, 3600);

            var cache = new MemoryCache("mtest");
            for (int i = 0; i < 10000; i++)
            {
                var ci = new CacheItem("test" + i, new byte[10000], "test");
                cache.Add(ci, cp);
            }



            var cache1 = new MemoryCache("mtest");
            var item = cache1["test1"]; //返回null

这里两个实例无法共享内存?那要这东西有什么用?

阅读 6.9k
2 个回答

public static

新手上路,请多包涵
public static class Cache{
 public  static  MemoryCache Cache=new MemoryCache("tttt");
   
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
logo
Microsoft
子站问答
访问
宣传栏