• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# CacheStorage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



CacheStorage类属于命名空间,在下文中一共展示了CacheStorage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: ThrowsArgumentNullExceptionForNullKey

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

                ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() =>
                {
                    var value = cache.Get(null);
                    Assert.IsNull(value);
                });
            }
开发者ID:paytonli2013,项目名称:Catel,代码行数:10,代码来源:CacheStorageFacts.cs


示例3: RunMultipleThreadsWithRandomAccessCalls

            public void RunMultipleThreadsWithRandomAccessCalls()
            {
                var cacheStorage = new CacheStorage<Guid, int>(() => ExpirationPolicy.Duration(TimeSpan.FromMilliseconds(1)));

                var threads = new List<Thread>();
                for (int i = 0; i < 25; i++)
                {
                    var thread = new Thread(() =>
                    {
                        var random = new Random();

                        for (int j = 0; j < 10000; j++)
                        {
                            var randomGuid = _randomGuids[random.Next(0, 9)];
                            cacheStorage.GetFromCacheOrFetch(randomGuid, () =>
                            {
                                var threadId = Thread.CurrentThread.ManagedThreadId;
                                Log.Info("Key '{0}' is now controlled by thread '{1}'", randomGuid, threadId);
                                return threadId;
                            });

                            ThreadHelper.Sleep(1);
                        }
                    });

                    threads.Add(thread);
                    thread.Start();
                }

                while (true)
                {
                    bool anyThreadAlive = false;

                    foreach (var thread in threads)
                    {
                        if (thread.IsAlive)
                        {
                            anyThreadAlive = true;
                            break;
                        }
                    }

                    if (!anyThreadAlive)
                    {
                        break;
                    }

                    ThreadHelper.Sleep(500);
                }
            }
开发者ID:JaysonJG,项目名称:Catel,代码行数:50,代码来源:CacheStorageFacts.cs


示例4: RunMultipleThreadsWithRandomAccessCalls

            private void RunMultipleThreadsWithRandomAccessCalls(Func<ICacheStorage<Guid, int>, Guid, int> retrievalFunc)
            {
                var cacheStorage = new CacheStorage<Guid, int>(() => ExpirationPolicy.Duration(TimeSpan.FromMilliseconds(250)));

                var threads = new List<Thread>();
                for (var i = 0; i < 50; i++)
                {
                    var thread = new Thread(() =>
                    {
                        var random = new Random();

                        for (var j = 0; j < 1000; j++)
                        {
                            var randomGuid = _randomGuids[random.Next(0, 9)];

                            retrievalFunc(cacheStorage, randomGuid);

                            ThreadHelper.Sleep(10);
                        }
                    });

                    threads.Add(thread);
                    thread.Start();
                }

                while (true)
                {
                    var anyThreadAlive = false;

                    foreach (var thread in threads)
                    {
                        if (thread.IsAlive)
                        {
                            anyThreadAlive = true;
                            break;
                        }
                    }

                    if (!anyThreadAlive)
                    {
                        break;
                    }

                    ThreadHelper.Sleep(500);
                }
            }
开发者ID:Catel,项目名称:Catel,代码行数:46,代码来源:CacheStorageFacts.cs


示例5: LoadTexture

        public static int LoadTexture(string filename, CacheStorage cache)
        {
            GL.ActiveTexture(TextureUnit.Texture0);

            filename = filename.ToLower();
            
            if (cache.materials.ContainsKey(filename))
            {
               // Console.WriteLine("[CACHE HIT] " + filename);
                return cache.materials[filename];
            }

            //Console.WriteLine("[CACHE MISS] " + filename);

            int textureId = GL.GenTexture();

            var blp = new BLPReader();

            blp.LoadBLP(filename);

            if (blp.bmp == null)
            {
                throw new Exception("BMP is null!");
            }
            else
            {
                GL.BindTexture(TextureTarget.Texture2D, textureId);
                cache.materials.Add(filename, textureId);
                System.Drawing.Imaging.BitmapData bmp_data = blp.bmp.LockBits(new System.Drawing.Rectangle(0, 0, blp.bmp.Width, blp.bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp_data.Width, bmp_data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
                blp.bmp.UnlockBits(bmp_data);
            }

            // Console.WriteLine("[CACHE ADD] " + filename);

            return textureId;
        }
开发者ID:Ser0ja,项目名称:WoWFormatTest,代码行数:41,代码来源:BLPLoader.cs


示例6: DisposesExpiredItemWhenDisposingNotEnabledButForcedByEventArgs

            public void DisposesExpiredItemWhenDisposingNotEnabledButForcedByEventArgs()
            {
                var disposable = new CustomDisposable();
                var cache = new CacheStorage<string, CustomDisposable>();
                cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);
                cache.Expired += (sender, e) =>
                {
                    e.Dispose = true;
                };

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

                ThreadHelper.Sleep(750);

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


示例7: 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


示例8: 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


示例9: AddsAndExpiresSeveralItems

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

                for (int i = 0; i < 5; i++)
                {
                    ThreadHelper.Sleep(1000);

                    int innerI = i;
                    var value = cache.GetFromCacheOrFetch("key", () => innerI, expiration: TimeSpan.FromMilliseconds(250));

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


示例10: 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


示例11: 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


示例12: 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


示例13: ThrowsArgumentNullExceptionForNullFunction

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

                ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => cache.GetFromCacheOrFetch("1", null));
            }
开发者ID:Catel,项目名称:Catel,代码行数:6,代码来源: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: AddsAndExpiresSeveralItems

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

                for (int i = 0; i < 5; i++)
                {
                    var value = cache.GetFromCacheOrFetch("key", () => i, expiration: new TimeSpan(0, 0, 1));

                    Assert.AreEqual(i, value);

                    ThreadHelper.Sleep(2000);
                }
            }
开发者ID:paytonli2013,项目名称:Catel,代码行数:13,代码来源:CacheStorageFacts.cs


示例16: DoesNotRaiseExpiredEventOnClearStorage

            public void DoesNotRaiseExpiredEventOnClearStorage()
            {
                var counter = 0;
                var cache = new CacheStorage<string, int>();
                cache.Add("1", 1);
                cache.Expired += (sender, e) => counter++;

                Assert.AreEqual(0, counter);
            }
开发者ID:Catel,项目名称:Catel,代码行数:9,代码来源:CacheStorageFacts.cs


示例17: 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


示例18: ThrowsArgumentNullExceptionForNullValueIfNotAllowNullValues

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

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


示例19: 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


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CacheType类代码示例发布时间:2022-05-24
下一篇:
C# CacheManager类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap