public void Resource_with_custom_configuration_expired_by_TTI() { // Make the default TTL 10 minutes, but IAccounts expire in 1 second var cacheProvider = RedisCaches.NewRedisCacheProvider() .WithRedisConnection(this.fixture.Connection) .WithDefaultTimeToIdle(TimeSpan.FromMinutes(10)) .WithCache(Caches.ForResource <IAccount>() .WithTimeToIdle(TimeSpan.FromSeconds(1))) .Build(); this.CreateClient(cacheProvider); this.fakeHttpClient.SetupGet("/groups/group1", 200, FakeJson.Group); this.fakeHttpClient.SetupGet("/accounts/foobarAccount", 200, FakeJson.Account); var group = this.client.GetResource <IGroup>("https://api.stormpath.com/v1/groups/group1"); var account = this.client.GetResource <IAccount>("https://api.stormpath.com/v1/accounts/foobarAccount"); this.fakeHttpClient.Calls.Count.ShouldBe(2); Thread.Sleep(1500); this.client.GetResource <IAccount>(account.Href); this.fakeHttpClient.Calls.Count.ShouldBe(3); this.client.GetResource <IGroup>(group.Href); this.fakeHttpClient.Calls.Count.ShouldBe(3); }
public void Combining_configuration_options() { var cacheProvider = Caches.NewInMemoryCacheProvider() .WithDefaultTimeToLive(TimeSpan.FromMinutes(30)) .WithDefaultTimeToIdle(TimeSpan.FromMinutes(30)) .WithCache(Caches .ForResource <Account.IAccount>() .WithTimeToLive(TimeSpan.FromHours(2))) .WithCache(Caches .ForResource <Application.IApplication>() .WithTimeToIdle(TimeSpan.FromHours(6)) .WithTimeToLive(TimeSpan.FromHours(6))) .Build() as ISynchronousCacheProvider; var accountCache = cacheProvider.GetSyncCache(nameof(Account.IAccount)); var applicationCache = cacheProvider.GetSyncCache(nameof(Application.IApplication)); var directoryCache = cacheProvider.GetSyncCache(nameof(Directory.IDirectory)); accountCache.TimeToLive.ShouldBe(TimeSpan.FromHours(2)); accountCache.TimeToIdle.ShouldBe(TimeSpan.FromMinutes(30)); applicationCache.TimeToLive.ShouldBe(TimeSpan.FromHours(6)); applicationCache.TimeToIdle.ShouldBe(TimeSpan.FromHours(6)); directoryCache.TimeToLive.ShouldBe(TimeSpan.FromMinutes(30)); directoryCache.TimeToIdle.ShouldBe(TimeSpan.FromMinutes(30)); }