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 Resource_is_cached_indefinitely()
        {
            var cacheProvider = RedisCaches.NewRedisCacheProvider()
                                .WithRedisConnection(this.fixture.Connection)
                                .Build();

            this.CreateClient(cacheProvider);
            this.fakeHttpClient.SetupGet("/accounts/foobarAccount", 200, FakeJson.Account);

            // Prime the cache
            var account = this.client.GetResource <IAccount>("https://api.stormpath.com/v1/accounts/foobarAccount");

            // All cache hits
            this.client.GetResource <IAccount>(account.Href);
            this.client.GetResource <IAccount>(account.Href);
            this.client.GetResource <IAccount>(account.Href);

            var db     = this.fixture.Connection.GetDatabase();
            var key    = TestHelper.CreateKey(account);
            var cached = db.StringGetWithExpiry(key);

            cached.Expiry.ShouldBeNull(); // No TTI
            cached.Value.ToString().ShouldNotBeNullOrEmpty();
            this.fakeHttpClient.Calls.Count.ShouldBe(1);
        }
Beispiel #3
0
        public async Task Resource_expired_by_TTI()
        {
            var cacheProvider = RedisCaches.NewRedisCacheProvider()
                                .WithRedisConnection(this.fixture.Connection)
                                .WithDefaultTimeToIdle(TimeSpan.FromSeconds(1))
                                .Build();

            this.CreateClient(cacheProvider);
            this.fakeHttpClient.SetupGet("/accounts/foobarAccount", 200, FakeJson.Account);

            var account = await this.client.GetResourceAsync <IAccount>("https://api.stormpath.com/v1/accounts/foobarAccount");

            await this.client.GetResourceAsync <IAccount>(account.Href);

            await this.client.GetResourceAsync <IAccount>(account.Href);

            this.fakeHttpClient.Calls.Count.ShouldBe(1);

            await Task.Delay(1500);

            await this.client.GetResourceAsync <IAccount>(account.Href);

            await this.client.GetResourceAsync <IAccount>(account.Href);

            this.fakeHttpClient.Calls.Count.ShouldBe(2);
        }
        public void Resource_expired_by_TTL()
        {
            var cacheProvider = RedisCaches.NewRedisCacheProvider()
                                .WithRedisConnection(this.fixture.Connection)
                                .WithDefaultTimeToLive(TimeSpan.FromSeconds(1))
                                .Build();

            this.CreateClient(cacheProvider);
            this.fakeHttpClient.SetupGet("/accounts/foobarAccount", 200, FakeJson.Account);

            var account = this.client.GetResource <IAccount>("https://api.stormpath.com/v1/accounts/foobarAccount");

            this.client.GetResource <IAccount>(account.Href);
            this.client.GetResource <IAccount>(account.Href);
            this.fakeHttpClient.Calls.Count.ShouldBe(1);

            Thread.Sleep(1500);

            this.client.GetResource <IAccount>(account.Href);
            this.client.GetResource <IAccount>(account.Href);
            this.fakeHttpClient.Calls.Count.ShouldBe(2);
        }