diff --git a/src/Ocelot/Cache/RegionsGetter.cs b/src/Ocelot/Cache/RegionsGetter.cs index 1c331c2a..ae87a49f 100644 --- a/src/Ocelot/Cache/RegionsGetter.cs +++ b/src/Ocelot/Cache/RegionsGetter.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Ocelot.Configuration.Provider; using Ocelot.Logging; @@ -33,9 +34,11 @@ namespace Ocelot.Cache return new List(); } + var cachedReRoutes = config.Data.ReRoutes.Where(x => x.IsCached); + var regions = new List(); - foreach(var reRoute in config.Data.ReRoutes) + foreach(var reRoute in cachedReRoutes) { var region = _creator.Region(reRoute); regions.Add(region); diff --git a/src/Ocelot/Controllers/OutputCacheController.cs b/src/Ocelot/Controllers/OutputCacheController.cs index 04150a5f..67a07d07 100644 --- a/src/Ocelot/Controllers/OutputCacheController.cs +++ b/src/Ocelot/Controllers/OutputCacheController.cs @@ -7,7 +7,7 @@ using Ocelot.Configuration.Provider; namespace Ocelot.Controllers { [Authorize] - [Route("cache")] + [Route("outputcache")] public class OutputCacheController : Controller { private IOcelotCache _cache; diff --git a/test/Ocelot.IntegrationTests/AdministrationTests.cs b/test/Ocelot.IntegrationTests/AdministrationTests.cs index b03d587e..e0826b68 100644 --- a/test/Ocelot.IntegrationTests/AdministrationTests.cs +++ b/test/Ocelot.IntegrationTests/AdministrationTests.cs @@ -218,6 +218,63 @@ namespace Ocelot.IntegrationTests .BDDfy(); } + [Fact] + public void should_return_regions() + { + + var initialConfiguration = new FileConfiguration + { + GlobalConfiguration = new FileGlobalConfiguration + { + AdministrationPath = "/administration" + }, + ReRoutes = new List() + { + new FileReRoute() + { + DownstreamHost = "localhost", + DownstreamPort = 80, + DownstreamScheme = "https", + DownstreamPathTemplate = "/", + UpstreamHttpMethod = new List { "get" }, + UpstreamPathTemplate = "/", + FileCacheOptions = new FileCacheOptions + { + TtlSeconds = 10 + } + }, + new FileReRoute() + { + DownstreamHost = "localhost", + DownstreamPort = 80, + DownstreamScheme = "https", + DownstreamPathTemplate = "/", + UpstreamHttpMethod = new List { "get" }, + UpstreamPathTemplate = "/test", + FileCacheOptions = new FileCacheOptions + { + TtlSeconds = 10 + } + } + } + }; + + var expected = new List + { + "get /", + "get /test" + }; + + this.Given(x => GivenThereIsAConfiguration(initialConfiguration)) + .And(x => GivenOcelotIsRunning()) + .And(x => GivenIHaveAnOcelotToken("/administration")) + .And(x => GivenIHaveAddedATokenToMyRequest()) + .When(x => WhenIGetUrlOnTheApiGateway("/administration/outputcache")) + .Then(x => ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) + .And(x => ThenTheResponseShouldBe(expected)) + .BDDfy(); + } + private void GivenAnotherOcelotIsRunning(string baseUrl) { _httpClientTwo.BaseAddress = new Uri(baseUrl); @@ -256,6 +313,13 @@ namespace Ocelot.IntegrationTests _response = _httpClient.PostAsync(url, content).Result; } + private void ThenTheResponseShouldBe(List expected) + { + var content = _response.Content.ReadAsStringAsync().Result; + var result = JsonConvert.DeserializeObject>(content); + result.ShouldBe(expected); + } + private void ThenTheResponseShouldBe(FileConfiguration expected) { var response = JsonConvert.DeserializeObject(_response.Content.ReadAsStringAsync().Result); diff --git a/test/Ocelot.UnitTests/Cache/RegionsGetterTests.cs b/test/Ocelot.UnitTests/Cache/RegionsGetterTests.cs index 1f235daf..a7d2b662 100644 --- a/test/Ocelot.UnitTests/Cache/RegionsGetterTests.cs +++ b/test/Ocelot.UnitTests/Cache/RegionsGetterTests.cs @@ -38,9 +38,13 @@ namespace Ocelot.UnitTests.Cache [Fact] public void should_get_regions() { + var cacheOptions = new CacheOptions(12); + var reRoute = new ReRouteBuilder() .WithUpstreamHttpMethod(new List{"Get"}) .WithUpstreamPathTemplate("/") + .WithCacheOptions(cacheOptions) + .WithIsCached(true) .Build(); var reRoutes = new List @@ -62,7 +66,7 @@ namespace Ocelot.UnitTests.Cache .BDDfy(); } - [Fact] + [Fact] public void should_return_empty_regions() { var expected = new List();