当前位置: 首页>>代码示例>>C#>>正文


C# CacheItem.CacheOutOfDate方法代码示例

本文整理汇总了C#中CacheItem.CacheOutOfDate方法的典型用法代码示例。如果您正苦于以下问题:C# CacheItem.CacheOutOfDate方法的具体用法?C# CacheItem.CacheOutOfDate怎么用?C# CacheItem.CacheOutOfDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CacheItem的用法示例。


在下文中一共展示了CacheItem.CacheOutOfDate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestCacheOutOfDate

        public void TestCacheOutOfDate()
        {
            var cacheItem = new CacheItem<string>(() => TestString, MinuteTimeSpan);
            // Call Value to update cache.
            Assert.AreEqual(TestString, cacheItem.Value, "Cache has the wrong value.");
            Assert.IsFalse(cacheItem.CacheOutOfDate(), "Cache should not be out of date yet.");
            Thread.Sleep(MinuteTimeSpan);
            Assert.IsTrue(cacheItem.CacheOutOfDate(), "Cache should be out of date after the timespan.");

            // Now we call Value to update cache again.
            Assert.AreEqual(TestString, cacheItem.Value, "Cache has the wrong value.");
            Assert.IsFalse(cacheItem.CacheOutOfDate(), "Cache should not be out of date yet.");
        }
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-powershell,代码行数:13,代码来源:CacheItemTest.cs

示例2: TestGetValueWithUpdateFunction

 public void TestGetValueWithUpdateFunction()
 {
     var cacheItem = new CacheItem<string>(cacheLifetime: MinuteTimeSpan);
     // Without update function, we will get a null or empty string.
     Assert.IsTrue(string.IsNullOrEmpty(cacheItem.Value), "Cache should return default value without update function.");
     string value = cacheItem.GetValueWithUpdateFunction(() => TestString);
     Assert.AreEqual(value, TestString, "GetValueWithUpdateFunction returns the incorrect value.");
     Assert.IsFalse(cacheItem.CacheOutOfDate(), "Cache should not be out of date yet.");
 }
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-powershell,代码行数:9,代码来源:CacheItemTest.cs

示例3: TestGetValueWithoutUpdateFunction

        public void TestGetValueWithoutUpdateFunction()
        {
            string before = "before";
            string after = "after";
            string changingString = before;
            // This function returns changingString so if we change changingString, the function will return a different value.
            Func<string> testFunction = () =>
            {
                return changingString;
            };

            var cacheItem = new CacheItem<string>(testFunction, cacheLifetime: MinuteTimeSpan);
            Assert.AreEqual(cacheItem.Value, before, "Cache has the wrong value.");
            changingString = after;
            // Wait for a minute before calling Value again so the item will be updated.
            Thread.Sleep(MinuteTimeSpan);
            Assert.IsTrue(cacheItem.CacheOutOfDate(), "Cache should be out of date after the timespan.");
            Assert.AreEqual(cacheItem.GetLastValueWithoutUpdate(), before, "GetLastValueWithoutUpdate should return value before the update.");
            Assert.AreEqual(cacheItem.Value, after, "Cache has the wrong value.");
        }
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-powershell,代码行数:20,代码来源:CacheItemTest.cs


注:本文中的CacheItem.CacheOutOfDate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。