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


C# Cache.Initialize方法代码示例

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


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

示例1: should_keep_cache_if_versions_same

        public async Task should_keep_cache_if_versions_same()
        {
            var cacheConfiguration = new CacheConfiguration(1024, 5, 1024, 5);

            var cacheContainer = InitializeCacheContainer();
            var storage = (TestStorage)cacheContainer.Resolve<IStorage>();

            cacheContainer.Register<IVersionProvider, TestVersionProvider>().WithValue("version", new Version(1, 1));

            using (var cache = new Cache(cacheContainer, cacheConfiguration))
            {
                await cache.Initialize();
                //when at least one value set cache is written
                await cache.Set("some_entry", 42);
            }

            //cache should not be cleanued up if versions in storage and executing assembly differ
            cacheContainer.Register<IVersionProvider, TestVersionProvider>().WithValue("version", new Version(1, 1));
            using (var cache = new Cache(cacheContainer, cacheConfiguration))
            {
                await cache.Initialize();
                storage.KeyToStreams.Should().NotBeEmpty();
                cache.Get<Int32>("some_entry").Result.Value.Should().Be(42);
            }
        }
开发者ID:IvanLeonenko,项目名称:windows-cache,代码行数:25,代码来源:When_version_is_stored_in_cache.cs

示例2: Initialize

        public async void Initialize()
        {
            var cacheContainer = new CacheContainer();
            cacheContainer.Register<ILogger, TestLogger>();
            cacheContainer.Register<IVersionProvider, TestVersionProvider>().WithValue("version", new Version("1.0"));
            cacheContainer.Register<IStorage, TestStorage>();
            cacheContainer.Register<ISerializer, ProtoBufSerializer>().WithDependency("storage", typeof(IStorage).FullName).WithValue("userTypes", null);

            var cacheConfiguration = new CacheConfiguration(900, 6, 800, 5);

            _cache = new Cache(cacheContainer, cacheConfiguration);
            await _cache.Initialize();
            await _cache.Set("stringKey1", "stringValue1");
            Thread.Sleep(20);
            await _cache.Set("stringKey2", "stringValue2");
            Thread.Sleep(20);
            await _cache.Set("byteKey3", new byte[]{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24});
            Thread.Sleep(20);
            await _cache.Set("stringKey4", "stringValue4");
            Thread.Sleep(20);
            await _cache.Set("Int32Key", 42);
            Thread.Sleep(20);
            await _cache.Set("DateTimeKey", _dateTime);
            Thread.Sleep(20);
            await _cache.Set("floatKey", 13.37f);
            Thread.Sleep(20);
            await _cache.Set("decimalKey", 13.37m);

            await _cache.SaveMappingsAndCheckLimits(null);
        }
开发者ID:IvanLeonenko,项目名称:windows-cache,代码行数:30,代码来源:When_overall_and_in_memory_size_and_quantity_limits_exceeded.cs

示例3: ItemAddedPreviousToFailedAddIsRemovedCompletelyIfSecondAddFails

        public void ItemAddedPreviousToFailedAddIsRemovedCompletelyIfSecondAddFails()
        {
            TestConfigurationContext context = new TestConfigurationContext();
            using (IsolatedStorageBackingStore backingStore = new IsolatedStorageBackingStore("foo"))
            {
                CacheCapacityScavengingPolicy scavengingPolicy = new CacheCapacityScavengingPolicy("test", new CachingConfigurationView(context));

                Cache cache = new Cache(backingStore, scavengingPolicy);
                cache.Initialize(this);

                cache.Add("my", new SerializableClass());

                try
                {
                    cache.Add("my", new NonSerializableClass());
                    Assert.Fail("Should have thrown exception internally to Cache.Add");
                }
                catch (Exception)
                {
                    Assert.IsFalse(cache.Contains("my"));
                    Assert.AreEqual(0, backingStore.Count);

                    Hashtable isolatedStorageContents = backingStore.Load();
                    Assert.AreEqual(0, isolatedStorageContents.Count);
                }
            }
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:27,代码来源:CacheExceptionHandlingFixture.cs

示例4: Initialize

        public async void Initialize()
        {
            _cacheContainer = new CacheContainer();
            _cacheContainer.Register<ILogger, TestLogger>();
            _cacheContainer.Register<IVersionProvider, TestVersionProvider>().WithValue("version", new Version("1.0"));
            _cacheContainer.Register<IStorage, TestStorage>().AsSingleton();
            _cacheContainer.Register<ISerializer, ProtoBufSerializer>().WithDependency("storage", typeof(IStorage).FullName).WithValue("userTypes", null);

            var cacheConfiguration = new CacheConfiguration(2048, 6, 2048, 5);

            _cache = new Cache(_cacheContainer, cacheConfiguration);
            await _cache.Initialize();
        }
开发者ID:IvanLeonenko,项目名称:windows-cache,代码行数:13,代码来源:When_cache_cleared.cs

示例5: should_save_version_on_cache_create

 public async Task should_save_version_on_cache_create()
 {
     var version = new Version(5, 32);
     var cacheContainer = new CacheContainer();
     cacheContainer.Register<ILogger, TestLogger>();
     cacheContainer.Register<IVersionProvider, TestVersionProvider>().WithValue("version", version);
     cacheContainer.Register<IStorage, TestStorage>().AsSingleton();
     cacheContainer.Register<ISerializer, ProtoBufSerializer>().WithDependency("storage", typeof(IStorage).FullName).WithValue("userTypes", null);
     var cacheConfiguration = new CacheConfiguration(1024, 5, 1024, 5);
     var cache = new Cache(cacheContainer, cacheConfiguration);
     await cache.Initialize();
     var storage = (TestStorage)cacheContainer.Resolve<IStorage>();
     storage.KeyToStrings[Cache.VersionEntryName].Should().BeEquivalentTo(version.ToString());
 }
开发者ID:IvanLeonenko,项目名称:windows-cache,代码行数:14,代码来源:When_no_version_is_stored_after_cache_create.cs

示例6: Initialize

        public async void Initialize()
        {
            var cacheContainer = new CacheContainer();
            cacheContainer.Register<ILogger, TestLogger>();
            cacheContainer.Register<IVersionProvider, TestVersionProvider>().WithValue("version", new Version("1.0"));
            cacheContainer.Register<IStorage, TestStorage>();
            cacheContainer.Register<ISerializer, ProtoBufSerializer>().WithDependency("storage", typeof(IStorage).FullName).WithValue("userTypes", null);

            var cacheConfiguration = new CacheConfiguration(2048, 6, 2048, 5);

            _cache = new Cache(cacheContainer, cacheConfiguration);
            await _cache.Initialize();
            await _cache.SetAsync("key1", "string1");
            await _cache.SetAsync("key2", 42);
            await _cache.SetAsync("key3", new byte[] { 12, 32, 54 });
        }
开发者ID:IvanLeonenko,项目名称:windows-cache,代码行数:16,代码来源:When_cache_set_with_async_method.cs

示例7: Initialize

        public async void Initialize()
        {
            var cacheContainer = new CacheContainer();
            cacheContainer.Register<ILogger, TestLogger>();
            cacheContainer.Register<IVersionProvider, TestVersionProvider>().WithValue("version", new Version("1.0"));
            cacheContainer.Register<IStorage, TestStorage>();
            cacheContainer.Register<ISerializer, ProtoBufSerializer>().WithDependency("storage", typeof(IStorage).FullName).WithValue("userTypes", null);

            var cacheConfiguration = new CacheConfiguration(2048, 6, 2048, 5);

            _cache = new Cache(cacheContainer, cacheConfiguration);
            await _cache.Initialize();
            await _cache.Set("key1", "string1", TimeSpan.FromMilliseconds(1));
            
            Thread.Sleep(10);
        }
开发者ID:IvanLeonenko,项目名称:windows-cache,代码行数:16,代码来源:When_cache_entry_expired.cs

示例8: Initialize

        public async void Initialize()
        {
            var cacheContainer = new CacheContainer();
            cacheContainer.Register<ILogger, TestLogger>();
            cacheContainer.Register<IVersionProvider, TestVersionProvider>().WithValue("version", new Version("1.0"));
            cacheContainer.Register<IStorage, TestStorage>();
            cacheContainer.Register<ISerializer, ProtoBufSerializer>().WithDependency("storage", typeof(IStorage).FullName).WithValue("userTypes", null);

            var cacheConfiguration = new CacheConfiguration(2048, 6, 1024, 6);

            _cache = new Cache(cacheContainer, cacheConfiguration);
            await _cache.Initialize();
            await _cache.Set("strinKey1", "stringValue1");
            await _cache.Set("strinKey2", "stringValue2");
            await _cache.Set("someBytes", new byte[] { 12, 32, 43 });
            await _cache.Set("Int32Key1", 1);
            await _cache.Set("dateTimeKey1", _dateTime);

        }
开发者ID:IvanLeonenko,项目名称:windows-cache,代码行数:19,代码来源:When_limits_not_exceeded.cs

示例9: ExceptionThrownDuringAddResultsInObjectBeingRemovedFromCacheCompletely

        public void ExceptionThrownDuringAddResultsInObjectBeingRemovedFromCacheCompletely()
        {
            MockBackingStore backingStore = new MockBackingStore();
            CacheCapacityScavengingPolicy scavengingPolicy = new CacheCapacityScavengingPolicy(10);
            CachingInstrumentationProvider instrumentationProvider = new CachingInstrumentationProvider();

            Cache cache = new Cache(backingStore, scavengingPolicy, instrumentationProvider);
            cache.Initialize(this);

            try
            {
                cache.Add("foo", "bar");
                Assert.Fail("Should have thrown exception thrown internally to Cache.Add");
            }
            catch (Exception)
            {
                Assert.IsFalse(cache.Contains("foo"));
                Assert.AreEqual(1, backingStore.removalCount);
            }
        }
开发者ID:bnantz,项目名称:NCS-V2-0,代码行数:20,代码来源:CacheExceptionHandlingFixture.cs

示例10: ExceptionThrownDuringAddResultsInObjectBeingRemovedFromCacheCompletely

        public void ExceptionThrownDuringAddResultsInObjectBeingRemovedFromCacheCompletely()
        {
            TestConfigurationContext context = new TestConfigurationContext();
            MockBackingStore backingStore = new MockBackingStore();
            CacheCapacityScavengingPolicy scavengingPolicy = new CacheCapacityScavengingPolicy("test", new CachingConfigurationView(context));

            Cache cache = new Cache(backingStore, scavengingPolicy);
            cache.Initialize(this);

            try
            {
                cache.Add("foo", "bar");
                Assert.Fail("Should have thrown exception thrown internally to Cache.Add");
            }
            catch (Exception)
            {
                Assert.IsFalse(cache.Contains("foo"));
                Assert.AreEqual(1, backingStore.removalCount);
            }
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:20,代码来源:CacheExceptionHandlingFixture.cs

示例11: ExceptionThrownDuringAddIntoIsolatedStorageAllowsItemToBeReaddedLater

        public void ExceptionThrownDuringAddIntoIsolatedStorageAllowsItemToBeReaddedLater()
        {
            using (IsolatedStorageBackingStore backingStore = new IsolatedStorageBackingStore("foo", null))
            {
                CacheCapacityScavengingPolicy scavengingPolicy = new CacheCapacityScavengingPolicy(10);
                CachingInstrumentationProvider instrumentationProvider = new CachingInstrumentationProvider();

                Cache cache = new Cache(backingStore, scavengingPolicy, instrumentationProvider);
                cache.Initialize(this);

                try
                {
                    cache.Add("my", new NonSerializableClass());
                    Assert.Fail("Should have thrown exception internally to Cache.Add");
                }
                catch (Exception)
                {
                    cache.Add("my", new SerializableClass());
                    Assert.IsTrue(cache.Contains("my"));
                }
            }
        }
开发者ID:bnantz,项目名称:NCS-V2-0,代码行数:22,代码来源:CacheExceptionHandlingFixture.cs

示例12: ExceptionThrownDuringAddIntoIsolatedStorageAllowsItemToBeReaddedLater

        public void ExceptionThrownDuringAddIntoIsolatedStorageAllowsItemToBeReaddedLater()
        {
            TestConfigurationContext context = new TestConfigurationContext();
            using (IsolatedStorageBackingStore backingStore = new IsolatedStorageBackingStore("foo"))
            {
                CacheCapacityScavengingPolicy scavengingPolicy = new CacheCapacityScavengingPolicy("test", new CachingConfigurationView(context));

                Cache cache = new Cache(backingStore, scavengingPolicy);
                cache.Initialize(this);

                try
                {
                    cache.Add("my", new NonSerializableClass());
                    Assert.Fail("Should have thrown exception internally to Cache.Add");
                }
                catch (Exception)
                {
                    cache.Add("my", new SerializableClass());
                    Assert.IsTrue(cache.Contains("my"));
                }
            }
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:22,代码来源:CacheExceptionHandlingFixture.cs

示例13: Initialize

        public async void Initialize()
        {
            var cacheContainer = new CacheContainer();
            cacheContainer.Register<ILogger, TestLogger>();
            cacheContainer.Register<IVersionProvider, TestVersionProvider>().WithValue("version", new Version("1.0"));
            cacheContainer.Register<IStorage, TestStorage>();
            cacheContainer.Register<ISerializer, ProtoBufSerializer>().WithDependency("storage", typeof(IStorage).FullName).WithValue("userTypes", null);

            var cacheConfiguration = new CacheConfiguration(500, 10, 500, 5);

            _cache = new Cache(cacheContainer, cacheConfiguration);
            await _cache.Initialize();
            await _cache.Set("stringKey1", "stringValue1");
            Thread.Sleep(20);
            await _cache.Set("stringKey2", "stringValue2");
            Thread.Sleep(20);
            await _cache.Set("stringKey3", "stringValue3");
            Thread.Sleep(20);
            await _cache.Set("stringKey4", "stringValue4");
            Thread.Sleep(20);
            await _cache.Set("Int32Key", 42);
            await _cache.SaveMappingsAndCheckLimits(null);
        }
开发者ID:IvanLeonenko,项目名称:windows-cache,代码行数:23,代码来源:When_overall_and_in_memory_size_limits_exceeded.cs

示例14: GetSettings

        public static WatcherSettings GetSettings()
        {
            var maxWaitTime = 3000;

            var file2Deleted = false;
            var file3Created = false;

            var dir2Deleted = false;
            var dir3Created = false;

            var changeDir = Path.GetTempFileName();
            changeDir = Path.Combine(
                Path.GetDirectoryName(changeDir),
                "changedir_" + Path.GetFileNameWithoutExtension(changeDir));
            Directory.CreateDirectory(changeDir);
            var subdir = Path.Combine(changeDir, "subdir");
            var subdirDelete = Path.Combine(changeDir, "subdirdelete");
            var dir2 = Path.Combine(changeDir, "subdir1");
            var dir3 = Path.Combine(changeDir, "subdir2");
            var file = Path.Combine(subdir, "myfile.txt");
            var file2 = Path.Combine(changeDir, "MovedFile.txt");
            var file3 = file2 + ".again";
            var fileContentChange = Path.Combine(changeDir, "contentToChange.txt");
            Directory.CreateDirectory(dir2);
            Directory.CreateDirectory(subdirDelete);
            File.WriteAllText(fileContentChange, "to be changed");
            File.WriteAllText(file2, "hey");

            var cache = new Cache(changeDir, () => false);
            cache.Initialize();

            Func<bool> fullSupport = () => {
                return
                    _canDetectDirectoryCreate &&
                    _canDetectDirectoryDelete &&
                    dir2Deleted && dir3Created &&
                    _canDetectFileCreate &&
                    _canDetectFileChange &&
                    _canDetectFileDelete &&
                    file2Deleted && file3Created;
            };

            var fsw = new FSW(
                changeDir,
                (s) => {
                    cache.Patch(new Change(ChangeType.DirectoryCreated, s));
                    _canDetectDirectoryCreate = true;
                    if (s == dir3)
                        dir3Created = true;
                },
                (s) => {
                    cache.Patch(new Change(ChangeType.DirectoryDeleted, s));
                    _canDetectDirectoryDelete = true;
                    if (s == dir2)
                        dir2Deleted = true;
                },
                (s) => {
                    _canDetectFileCreate = true;
                    if (s == file3)
                        file3Created = true;
                },
                (s) => _canDetectFileChange = true,
                (s) => {
                    _canDetectFileDelete = true;
                    if (s == file2)
                        file2Deleted = true;
                },
                (s) => {},
                cache);
            fsw.Start();

            var fileChanges = new Thread(() => {
                var startTime = DateTime.Now;
                Directory.CreateDirectory(subdir);
                File.WriteAllText(file, "hey");
                using (var writer = File.AppendText(fileContentChange)) {
                    writer.Write("moar content");
                }
                File.Move(file2, file3);
                File.Delete(file);
                Directory.Move(dir2, dir3);
                Directory.Delete(subdirDelete);
                while (!fullSupport() && timeSince(startTime) < maxWaitTime)
                    Thread.Sleep(10);
            });
            fileChanges.Start();
            fileChanges.Join();

            fsw.Stop();

            Directory.Delete(dir3);
            if (Directory.Exists(subdirDelete))
                Directory.Delete(subdirDelete);
            File.Delete(fileContentChange);
            File.Delete(file3);
            Directory.Delete(subdir);
            Directory.Delete(changeDir);

            return new WatcherSettings(
                _canDetectDirectoryCreate,
//.........这里部分代码省略.........
开发者ID:rhwy,项目名称:FSWatcher,代码行数:101,代码来源:WatcherSettings.cs


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