HttpContext
// 写
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 1; i <= 100000; i++)
{
var m = new Man()
{
age = 1,
Height = 2
};
HttpContext.Current.Cache[i.ToString()] = m;
}
sw.Stop();
Debug.WriteLine(sw.ElapsedMilliseconds);
// 读
sw.Start();
for (int j = 1; j <= 100000; j++)
{
var m = HttpContext.Current.Cache[j.ToString()];
}
sw.Stop();
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 1; i <= 100000; i++)
{
var m = new Man()
{
age = 1,
Height = 2
};
HttpContext.Current.Cache[i.ToString()] = m;
}
sw.Stop();
Debug.WriteLine(sw.ElapsedMilliseconds);
// 读
sw.Start();
for (int j = 1; j <= 100000; j++)
{
var m = HttpContext.Current.Cache[j.ToString()];
}
sw.Stop();
Debug.WriteLine(sw.ElapsedMilliseconds);
结果是:
181
249
Appfabric
var dcf = new DataCacheFactory();
var cache = dcf.GetCache("default");
// 写
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 1; i <= 100000; i++)
{
var m = new Man()
{
age = 1,
Height = 2
};
cache.Put(i.ToString(), m);
}
sw.Stop();
Debug.WriteLine(sw.ElapsedMilliseconds);
// 读
sw.Start();
for (int j = 1; j <= 100000;j++ )
{
var m = cache.Get(j.ToString());
}
sw.Stop();
var cache = dcf.GetCache("default");
// 写
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 1; i <= 100000; i++)
{
var m = new Man()
{
age = 1,
Height = 2
};
cache.Put(i.ToString(), m);
}
sw.Stop();
Debug.WriteLine(sw.ElapsedMilliseconds);
// 读
sw.Start();
for (int j = 1; j <= 100000;j++ )
{
var m = cache.Get(j.ToString());
}
sw.Stop();
Debug.WriteLine(sw.ElapsedMilliseconds);
结果是
133979 (写的时间)
263803 (读+写的总时间)
补充Application的测试结果:
103
184
// 写
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 1; i <= 100000; i++)
{
var m = new Man()
{
age = 1,
Height = 2
};
Application[i.ToString()] = m;
}
sw.Stop();
Debug.WriteLine(sw.ElapsedMilliseconds);
// 读
sw.Start();
for (int j = 1; j <= 100000; j++)
{
var m = Application[j.ToString()];
}
sw.Stop();
Debug.WriteLine(sw.ElapsedMilliseconds);
sw.Start();
for (int i = 1; i <= 100000; i++)
{
var m = new Man()
{
age = 1,
Height = 2
};
Application[i.ToString()] = m;
}
sw.Stop();
Debug.WriteLine(sw.ElapsedMilliseconds);
// 读
sw.Start();
for (int j = 1; j <= 100000; j++)
{
var m = Application[j.ToString()];
}
sw.Stop();
Debug.WriteLine(sw.ElapsedMilliseconds);