forked from aiska/BpmNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryCacheTest.cs
More file actions
64 lines (62 loc) · 2.07 KB
/
Copy pathMemoryCacheTest.cs
File metadata and controls
64 lines (62 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Runtime.Caching;
using System.Diagnostics;
using BPMNET.Entity;
namespace BPMNET.UnitTest
{
[TestClass]
public class MemoryCacheTest
{
[TestMethod]
public void TestMethod1()
{
Stopwatch w = new Stopwatch();
int count = 30;
w.Start();
CacheItemPolicy policy = new CacheItemPolicy();
policy.SlidingExpiration = new TimeSpan(1, 0, 0);
MemoryCache cache = new MemoryCache("test");
string[] keys = new string[count];
for (int i = 0; i < count; i++)
{
keys[i] = Guid.NewGuid().ToString();
}
w.Stop();
Debug.WriteLine("Create Instance : " + w.ElapsedMilliseconds + "ms");
w.Restart();
for (int i = 0; i < count; i++)
{
var t = new ProcessDefinition();
t.ProcessDefinitionId = keys[i];
cache.Add(keys[i], t, policy);
}
w.Stop();
Debug.WriteLine("Add " + count + " Test : " + w.ElapsedMilliseconds + "ms");
w.Restart();
for (int i = 0; i < count; i++)
{
var val = cache.Get(keys[i]);
}
w.Stop();
Debug.WriteLine("Get " + count + " Test : " + w.ElapsedMilliseconds + "ms");
w.Restart();
foreach (var item in cache)
{
var val = item.Value as ProcessDefinition;
val.UpdateDate = DateTime.Now;
val.Name = "update";
cache.Set(item.Key, val, policy);
}
w.Stop();
Debug.WriteLine("Update " + count + " Test : " + w.ElapsedMilliseconds + "ms");
w.Restart();
for (int i = 0; i < count; i++)
{
cache.Remove(keys[i]);
}
w.Stop();
Debug.WriteLine("Remove " + count + " Test : " + w.ElapsedMilliseconds + "ms");
}
}
}