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


C# CacheStorage.Add方法代码示例

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


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

示例1: ReturnsRightValueForExistingKey

            public void ReturnsRightValueForExistingKey()
            {
                var cache = new CacheStorage<string, int>();
                cache.Add("1", 1);
                cache.Add("2", 2);

                Assert.AreEqual(2, cache.Get("2"));
            }
开发者ID:paytonli2013,项目名称:Catel,代码行数:8,代码来源:CacheStorageFacts.cs

示例2: RaisesExpiringEventWithCorrectEventArgsWhenItemExpires

            public void RaisesExpiringEventWithCorrectEventArgsWhenItemExpires()
            {
                var key = "1";
                var expirationPolicy = new SlidingExpirationPolicy(TimeSpan.FromMilliseconds(250));
                var value = 1;
                var evKey = (string)null;
                var evExpirationPolicy = default(ExpirationPolicy);
                var evValue = 0;

                var cache = new CacheStorage<string, int>();
                cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);
                cache.Expiring += (sender, e) =>
                {
                    evKey = e.Key;
                    evExpirationPolicy = e.ExpirationPolicy;
                    evValue = e.Value;
                };

                cache.Add(key, value, expirationPolicy);

                ThreadHelper.Sleep(750);

                Assert.AreEqual(key, evKey);
                Assert.AreEqual(expirationPolicy, evExpirationPolicy);
                Assert.AreEqual(value, evValue);
            }
开发者ID:Catel,项目名称:Catel,代码行数:26,代码来源:CacheStorageFacts.cs

示例3: AutomaticallyRemovesExpiredItemsOfACacheStorageWithDefaultExpirationPolicyInitializationCode

            public void AutomaticallyRemovesExpiredItemsOfACacheStorageWithDefaultExpirationPolicyInitializationCode()
            {
                var cache = new CacheStorage<string, int>(() => ExpirationPolicy.Duration(TimeSpan.FromMilliseconds(250)));
                cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);

                cache.Add("1", 1);

                Assert.IsTrue(cache.Contains("1"));

                ThreadHelper.Sleep(750);

                Assert.IsFalse(cache.Contains("1"));
            }
开发者ID:Catel,项目名称:Catel,代码行数:13,代码来源:CacheStorageFacts.cs

示例4: AutomaticallyRemovesExpiredItems

            public void AutomaticallyRemovesExpiredItems()
            {
                var cache = new CacheStorage<string, int>();
                cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);

                cache.Add("1", 1, expiration: new TimeSpan(0, 0, 0, 0, 250));

                Assert.IsTrue(cache.Contains("1"));

                ThreadHelper.Sleep(750);

                Assert.IsFalse(cache.Contains("1"));
            }
开发者ID:Catel,项目名称:Catel,代码行数:13,代码来源:CacheStorageFacts.cs

示例5: IsAutomaticallyEnabledWhenStartedDisabledButAddingItemWithCustomExpirationPolicy

            public void IsAutomaticallyEnabledWhenStartedDisabledButAddingItemWithCustomExpirationPolicy()
            {
                var cache = new CacheStorage<string, int>();
                cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);

                cache.Add("1", 1, expiration: new TimeSpan(0, 0, 0, 0, 250));

                Assert.IsTrue(cache.Contains("1"));

                ThreadHelper.Sleep(750);

                Assert.IsFalse(cache.Contains("1"));
            }
开发者ID:Catel,项目名称:Catel,代码行数:13,代码来源:CacheStorageFacts.cs

示例6: DisposesItemOnRemoveWhenDisposingEnabled

            public void DisposesItemOnRemoveWhenDisposingEnabled()
            {
                var disposable = new CustomDisposable();
                var cache = new CacheStorage<string, CustomDisposable>();
                cache.DisposeValuesOnRemoval = true;
                cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);

                cache.Add("disposable", disposable, expiration: TimeSpan.FromMilliseconds(250));

                Assert.IsFalse(disposable.IsDiposed);

                cache.Remove("disposable");

                Assert.IsTrue(disposable.IsDiposed);
            }
开发者ID:Catel,项目名称:Catel,代码行数:15,代码来源:CacheStorageFacts.cs

示例7: DoesNotDisposeItemsOnClearWhenDisposingNotEnabled

            public void DoesNotDisposeItemsOnClearWhenDisposingNotEnabled()
            {
                var disposable = new CustomDisposable();
                var cache = new CacheStorage<string, CustomDisposable>();
                cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);

                cache.Add("disposable", disposable, expiration: TimeSpan.FromMilliseconds(250));

                Assert.IsFalse(disposable.IsDiposed);

                cache.Clear();

                Assert.IsFalse(disposable.IsDiposed);
            }
开发者ID:Catel,项目名称:Catel,代码行数:14,代码来源:CacheStorageFacts.cs

示例8: AddsNonExistingValue

            public void AddsNonExistingValue()
            {
                var cache = new CacheStorage<string, int>();
                cache.Add("1", 1);

                Assert.AreEqual(1, cache["1"]);
            }
开发者ID:Catel,项目名称:Catel,代码行数:7,代码来源:CacheStorageFacts.cs

示例9: AddsNonExistingValueForTrueOverride

            public void AddsNonExistingValueForTrueOverride()
            {
                var cache = new CacheStorage<string, int>();
                cache.Add("1", 1);
                cache.Add("1", 2, true);

                Assert.AreEqual(2, cache["1"]);
            }
开发者ID:Catel,项目名称:Catel,代码行数:8,代码来源:CacheStorageFacts.cs

示例10: ThrowsArgumentNullExceptionForNullKey

            public void ThrowsArgumentNullExceptionForNullKey()
            {
                var cache = new CacheStorage<string, int>();

                ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => cache.Add(null, 1));
            }
开发者ID:Catel,项目名称:Catel,代码行数:6,代码来源:CacheStorageFacts.cs

示例11: ThrowsArgumentNullExceptionForNullValueIfNotAllowNullValues

            public void ThrowsArgumentNullExceptionForNullValueIfNotAllowNullValues()
            {
                var cache = new CacheStorage<string, object>();

                ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => cache.Add(null, null));
            }
开发者ID:Catel,项目名称:Catel,代码行数:6,代码来源:CacheStorageFacts.cs

示例12: AddsItemToCacheWithOverrideAndReturnsIt

            public void AddsItemToCacheWithOverrideAndReturnsIt()
            {
                var cache = new CacheStorage<string, int>();

                cache.Add("1", 1);
                var value = cache.GetFromCacheOrFetch("1", () => 2, true);

                Assert.IsTrue(cache.Contains("1"));
                Assert.AreEqual(2, cache["1"]);
                Assert.AreEqual(2, value);
            }
开发者ID:Catel,项目名称:Catel,代码行数:11,代码来源:CacheStorageFacts.cs

示例13: ReturnsCachedItem

            public void ReturnsCachedItem()
            {
                var cache = new CacheStorage<string, int>();

                cache.Add("1", 1);
                var value = cache.GetFromCacheOrFetch("1", () => 2);

                Assert.IsTrue(cache.Contains("1"));
                Assert.AreEqual(1, cache["1"]);
                Assert.AreEqual(1, value);
            }
开发者ID:Catel,项目名称:Catel,代码行数:11,代码来源:CacheStorageFacts.cs

示例14: ReturnsTrueForExistingKey

            public void ReturnsTrueForExistingKey()
            {
                var cache = new CacheStorage<string, int>();
                cache.Add("1", 1);
                cache.Add("2", 2);

                Assert.IsTrue(cache.Contains("2"));
            }
开发者ID:Catel,项目名称:Catel,代码行数:8,代码来源:CacheStorageFacts.cs

示例15: ItemStaysInCacheWhenExpiringEventIsCanceled

            public void ItemStaysInCacheWhenExpiringEventIsCanceled()
            {
                var key = "1";
                var value = 1;

                var cache = new CacheStorage<string, int>();
                cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);
                cache.Expiring += (sender, e) =>
                {
                    e.Cancel = true;
                };

                cache.Add(key, value, expiration: new TimeSpan(0, 0, 0, 0, 250));

                ThreadHelper.Sleep(750);

                Assert.IsTrue(cache.Contains(key));
            }
开发者ID:Catel,项目名称:Catel,代码行数:18,代码来源:CacheStorageFacts.cs


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