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


C# PokerMemoryCache.CreateCacheEntryChangeMonitor方法代码示例

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


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

示例1: CreateCacheEntryChangeMonitor

		public void CreateCacheEntryChangeMonitor ()
		{
			var mc = new PokerMemoryCache ("MyCache");

			AssertExtensions.Throws<NotSupportedException> (() => {
				mc.CreateCacheEntryChangeMonitor (new string [] { "key" }, "region");
			}, "#A1-1");

			AssertExtensions.Throws<ArgumentNullException> (() => {
				mc.CreateCacheEntryChangeMonitor (null);
			}, "#A1-2");

			AssertExtensions.Throws<ArgumentException> (() => {
				mc.CreateCacheEntryChangeMonitor (new string [] {});
			}, "#A1-3");

			AssertExtensions.Throws<ArgumentException> (() => {
				mc.CreateCacheEntryChangeMonitor (new string [] { "key", null });
			}, "#A1-4");

			mc.Set ("key1", "value1", ObjectCache.InfiniteAbsoluteExpiration);
			mc.Set ("key2", "value2", ObjectCache.InfiniteAbsoluteExpiration);
			mc.Set ("key3", "value3", ObjectCache.InfiniteAbsoluteExpiration);

			CacheEntryChangeMonitor monitor = mc.CreateCacheEntryChangeMonitor (new string [] { "key1", "key2" });
			Assert.IsNotNull (monitor, "#A2-1");
			Assert.AreEqual ("System.Runtime.Caching.MemoryCacheEntryChangeMonitor", monitor.GetType ().ToString (), "#A2-2");
			Assert.AreEqual (2, monitor.CacheKeys.Count, "#A2-3");
			Assert.AreEqual ("key1", monitor.CacheKeys [0], "#A2-3-1");
			Assert.AreEqual ("key2", monitor.CacheKeys [1], "#A2-3-2");
			Assert.IsNull (monitor.RegionName, "#A2-4");
			// Since this comparison can fail from time to time, leaving it commented out
			//Assert.AreEqual (DateTimeOffset.UtcNow.ToString (), monitor.LastModified.ToString (), "#A2-5");
			Assert.IsFalse (monitor.HasChanged, "#A2-5");

			// The actual unique id is constructed from key names followed by the hex value of ticks of their last modifed time
			Assert.IsFalse (String.IsNullOrEmpty (monitor.UniqueId), "#A2-6");

			// There seems to be a bug in .NET 4.0 regarding the code below. MSDN says that non-existing keys will cause the
			// returned monitor instance to be marked as changed, but instead this exception is thrown:
			//
			// MonoTests.System.Runtime.Caching.MemoryCacheTest.CreateCacheEntryChangeMonitor:
			// System.ArgumentOutOfRangeException : The UTC time represented when the offset is applied must be between year 0 and 10,000.
			// Parameter name: offset
			// 
			// at System.DateTimeOffset.ValidateDate(DateTime dateTime, TimeSpan offset)
			// at System.DateTimeOffset..ctor(DateTime dateTime)
			// at System.Runtime.Caching.MemoryCacheEntryChangeMonitor.InitDisposableMembers(MemoryCache cache)
			// at System.Runtime.Caching.MemoryCache.CreateCacheEntryChangeMonitor(IEnumerable`1 keys, String regionName)
			// at MonoTests.Common.PokerMemoryCache.CreateCacheEntryChangeMonitor(IEnumerable`1 keys, String regionName) in C:\Users\grendel\documents\visual studio 2010\Projects\System.Runtime.Caching.Test\System.Runtime.Caching.Test\Common\PokerMemoryCache.cs:line 113
			// at MonoTests.System.Runtime.Caching.MemoryCacheTest.CreateCacheEntryChangeMonitor() in C:\Users\grendel\documents\visual studio 2010\Projects\System.Runtime.Caching.Test\System.Runtime.Caching.Test\System.Runtime.Caching\MemoryCacheTest.cs:line 275
			//
			// It's probably caused by the code passing a DateTime.MinValue to DateTimeOffset constructor for non-existing entries.
			// Until this (apparent) bug is fixed, Mono is going to implement the buggy behavior.
			//
#if true
			AssertExtensions.Throws<ArgumentOutOfRangeException> (() => {
				monitor = mc.CreateCacheEntryChangeMonitor (new string [] { "key1", "doesnotexist" });
			}, "#A3");
#else
			monitor = mc.CreateCacheEntryChangeMonitor (new string [] { "key1", "doesnotexist" });
			Assert.IsNotNull (monitor, "#A3-1");
			Assert.AreEqual ("System.Runtime.Caching.MemoryCacheEntryChangeMonitor", monitor.GetType ().ToString (), "#A3-2");
			Assert.AreEqual (1, monitor.CacheKeys.Count, "#A3-3");
			Assert.AreEqual ("key1", monitor.CacheKeys [0], "#A3-3-1");
			Assert.IsNull (monitor.RegionName, "#A3-4");
			Assert.IsTrue (monitor.HasChanged, "#A3-5");
#endif
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:69,代码来源:MemoryCacheTest.cs


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