mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 09:42:49 +08:00

* changed name to cache options to fix issue #146 * Add acceptance test that exposes JSON deserialization bug from issue #146 - Create InMemoryJsonHandle for CacheManager that mimics DictionaryHandle but uses ICacheSerializer to serialize/deserialize values instead of saving references - Add CacheManager.Serialization.Json package - Add StartupWithCustomCacheHandle class that extends Startup and overrides ConfigureServices to register InMemoryJsonHandle - Add GivenOcelotIsRunningUsingConsulToStoreConfigAndJsonSerializedCache method to initiate Ocelot with StartupWithCustomCacheHandle - Add test should_return_response_200_with_simple_url_when_using_jsonserialized_cache * Create Acceptance test that exposes issue #152 - Add GivenOcelotIsRunningUsingJsonSerializedCache() that initializes Ocelot with InMemoryJsonHandle - Add should_return_cached_response_when_using_jsonserialized_cache test * Change Consul port to 9502 on should_return_response_200_with_simple_url_when_using_jsonserialized_cache() test * Implement mapping of HttpResponseMessage to CachedResponse to enable distributed caching - Add CachedResponse class that holds HttpResponse data - Add mapping methods in OutputCacheMiddleware to create HttpResponseMessage from CachedResponse and vice versa - Replace HttpResponseMessage with CachedResponse in services registrations - Replace HttpResponseMessage with CachedResponse in OutputCacheController's IOcelotCache * Fix unit tests for OutputCacheMiddleware and OutputCacheController by replacing HttpResponseMessage with CachedResponse * Add .editorconfig with default identation settings (spaces with size 4) * Re-format broken files with new identation settings * Add Startup_WithConsul_And_CustomCacheHandle class - Use Startup_WithConsul_And_CustomCacheHandle in GivenOcelotIsRunningUsingConsulToStoreConfigAndJsonSerializedCache step * Do minor cleanups - Rename StartupWithCustomCacheHandle to Startup_WithCustomCacheHandle for better readability - Remove cachemanager settings Action in Startup since it is not used anymore * Drop Task in CreateHttpResponseMessage - unnecessary overhead * Make setters private in CachedResponse - Rework CreateCachedResponse to use new CachedResponse constructor
83 lines
2.7 KiB
C#
83 lines
2.7 KiB
C#
using System;
|
|
using CacheManager.Core;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using Ocelot.DependencyInjection;
|
|
using Ocelot.Middleware;
|
|
using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder;
|
|
using Ocelot.AcceptanceTests.Caching;
|
|
|
|
namespace Ocelot.AcceptanceTests
|
|
{
|
|
public class Startup
|
|
{
|
|
public Startup(IHostingEnvironment env)
|
|
{
|
|
var builder = new ConfigurationBuilder()
|
|
.SetBasePath(env.ContentRootPath)
|
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
|
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
|
|
.AddJsonFile("configuration.json")
|
|
.AddEnvironmentVariables();
|
|
|
|
Configuration = builder.Build();
|
|
}
|
|
|
|
public IConfigurationRoot Configuration { get; }
|
|
|
|
public virtual void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddOcelot(Configuration);
|
|
}
|
|
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
|
{
|
|
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
|
|
|
app.UseOcelot().Wait();
|
|
}
|
|
}
|
|
|
|
public class Startup_WithCustomCacheHandle : Startup
|
|
{
|
|
public Startup_WithCustomCacheHandle(IHostingEnvironment env) : base(env) { }
|
|
|
|
public override void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddOcelot(Configuration)
|
|
.AddCacheManager((x) =>
|
|
{
|
|
x.WithMicrosoftLogging(log =>
|
|
{
|
|
log.AddConsole(LogLevel.Debug);
|
|
})
|
|
.WithJsonSerializer()
|
|
.WithHandle(typeof(InMemoryJsonHandle<>));
|
|
});
|
|
}
|
|
}
|
|
|
|
public class Startup_WithConsul_And_CustomCacheHandle : Startup
|
|
{
|
|
public Startup_WithConsul_And_CustomCacheHandle(IHostingEnvironment env) : base(env) { }
|
|
|
|
public override void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddOcelot(Configuration)
|
|
.AddCacheManager((x) =>
|
|
{
|
|
x.WithMicrosoftLogging(log =>
|
|
{
|
|
log.AddConsole(LogLevel.Debug);
|
|
})
|
|
.WithJsonSerializer()
|
|
.WithHandle(typeof(InMemoryJsonHandle<>));
|
|
})
|
|
.AddStoreOcelotConfigurationInConsul();
|
|
}
|
|
}
|
|
}
|