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); } }
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); }
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(); }
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()); }
public async Task custom_config_cache_construction_should_work() { var cacheConfig = new CacheConfiguration(1024, 5, 1024, 5, TimeSpan.FromMinutes(1)); var cache = await PortableCacheFactory.GetCache(cacheConfig, null, "someCacheName2"); await cache.Set("key1", "stringValue"); cache.Size.Should().BeGreaterThan(0); cache.Count.Should().Be(1); cache.Get<string>("key1").Result.Value.Should().Be("stringValue"); await cache.Remove("key1"); cache.Count.Should().Be(0); cache.Size.Should().Be(0); cache.Get<string>("key1").Result.Should().BeNull(); }
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 }); }
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); }
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); }
public async Task custom_container_and_config_cache_construction_should_work() { var cacheContainer = new CacheContainer(); cacheContainer.Register<ILogger, DebugCacheLogger>(); cacheContainer.Register<IVersionProvider, PackageVersionProvider>(); cacheContainer.Register<IStorage, IsolatedStorage>().WithValue("cacheName", "cacheName"); cacheContainer.Register<ISerializer, ProtoBufSerializer>().WithDependency("storage", typeof(IStorage).FullName).WithValue("userTypes", null); var cacheConfig = new CacheConfiguration(1024, 5, 1024, 5, TimeSpan.FromMinutes(1)); var cache = await PortableCacheFactory.GetCache(cacheContainer, cacheConfig); await cache.Set("key1", "stringValue"); cache.Size.Should().BeGreaterThan(0); cache.Count.Should().Be(1); cache.Get<string>("key1").Result.Value.Should().Be("stringValue"); await cache.Remove("key1"); cache.Count.Should().Be(0); cache.Size.Should().Be(0); cache.Get<string>("key1").Result.Should().BeNull(); await cache.Clear(); }
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); }
public async Task <ICache> InMemoryCache(CacheContainer cacheContainer, CacheConfiguration cacheConfiguration) { cacheConfiguration.InMemoryOnly = true; return(await Cache(cacheContainer, cacheConfiguration)); }
public async Task <ICache> InMemoryCache(CacheConfiguration cacheConfiguration, IEnumerable <Type> userTypes = null, string cacheName = "default") { return(await InMemoryCache(GetDefaultCacheContainer(userTypes, cacheName), cacheConfiguration)); }