forked from ProxyKit/ProxyKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11_CachingWithCacheCow.cs
43 lines (39 loc) · 1.77 KB
/
11_CachingWithCacheCow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using CacheCow.Client;
using CacheCow.Common;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
namespace ProxyKit.Recipes
{
public class CachingWithCacheCow : Recipe<CachingWithCacheCow.Startup>
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Add the CacheCow stores to the service collection
// Note: using in-memory implementations here for brevity.
// See https://github.com/aliostad/CacheCow for full documentation.
services.AddSingleton<ICacheStore>(new InMemoryCacheStore(TimeSpan.FromMinutes(1)));
services.AddSingleton<IVaryHeaderStore>(new InMemoryVaryHeaderStore());
// We need to register the CacheCow caching handler. This will
// be used by the ProxyKit's HttpClient whose constructor
// takes the ICacheStore and IVaryHeaderStore implementations.
services.AddTransient<CachingHandler>();
services.AddProxy(httpClientBuilder =>
{
// Tell ProxyKit to use the CachingHandler in its HttpClient.
httpClientBuilder.AddHttpMessageHandler<CachingHandler>();
});
}
public void Configure(IApplicationBuilder app)
{
app.RunProxy(context => context
.ForwardTo("http://localhost:5001")
.CopyXForwardedHeaders() // copies the headers from the incoming requests
.AddXForwardedHeaders() // adds the current proxy proto/host/for/pathbase to the X-Forwarded headers
.Send());
}
}
}
}