本文整理汇总了C#中TestClass.Cache方法的典型用法代码示例。如果您正苦于以下问题:C# TestClass.Cache方法的具体用法?C# TestClass.Cache怎么用?C# TestClass.Cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestClass
的用法示例。
在下文中一共展示了TestClass.Cache方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CacheAlternitiveSyntaxThree
public void CacheAlternitiveSyntaxThree()
{
TestClass obj = new TestClass();
var sum = obj.Cache(x => x.Add(10, 1), "TenPlusOne");
Assert.Equal(11, sum);
}
示例2: CacheAcceptsClassArgumentsWithToStringOverride
public void CacheAcceptsClassArgumentsWithToStringOverride()
{
var int1 = new IntWrapper() { TheInt = 5 };
var int2 = new IntWrapper() { TheInt = 6 };
TestClass obj = new TestClass();
var sum = obj.Cache(x => x.AddIntWrapper(int1, int2));
Assert.Equal(11, sum);
}
示例3: CacheStoresData
public void CacheStoresData()
{
TestClass obj = new TestClass();
Stopwatch sw = new Stopwatch();
sw.Start();
var sum = obj.Cache(x => x.SlowAdd(1, 2));
var sum2 = obj.Cache(x => x.SlowAdd(1, 2));
sw.Stop();
Assert.Equal(3, sum);
Assert.Equal(3, sum2);
Assert.True(sw.ElapsedMilliseconds < 2500);
}
示例4: CacheSyntax
public void CacheSyntax()
{
TestClass obj = new TestClass();
var sum = obj.Cache(x => x.Add(2, 3));
Assert.Equal(5, sum);
}
示例5: SpeedTest
public void SpeedTest()
{
TestClass obj = new TestClass();
int sum;
int iterations = 10000;
Stopwatch sw = new Stopwatch();
Stopwatch sw2 = new Stopwatch();
Stopwatch sw3 = new Stopwatch();
sw.Start();
for (int x = 0; x < iterations; x++)
{
sum = obj.Cache(o => o.Add(1, 1));
}
sw.Stop();
sw2.Start();
for (int x = 0; x < iterations; x++)
{
sum = obj.Cache(o => o.Add(1, 2), "OnePlusTwo");
}
sw2.Stop();
sw3.Start();
for (int x = 0; x < iterations; x++)
{
if (MemoryCache.Default.Contains("testHash"))
{
sum = (int)MemoryCache.Default.Get("testHash");
}
else
{
sum = 1 + 1;
MemoryCache.Default.Set("testHash", sum, DateTimeOffset.Now.AddMilliseconds(2000));
}
}
sw3.Stop();
}