-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add WIP Redis example * Fix Redis example * Add Nearform as a known word * Increase the default cache timeout to 5s * Stop storing a manual TTL * Rename 'webfrontend' to 'web' * Disable local cache * Greatly increase the cache timeout to allow for debugging This is a sample, after all * Disable local cache (missed this in f7c6242) * Cleanup * Address static analysis concerns * Address ReSharper issues in Microsoft's template :) * Feat/use di properly (#2) * Switch to properly using DI 🤦♂️ * [WIP] Partially fix tests. No compilation errors, but most tests fail * [WIP] Fix some DI * Allow the caller to send in a cancellation token * Fix removal of items in CacheHelperTests * Remove an impossible test DI now handles the cache, we can't set it anymore * [WIP] ? * Fix SlowDownMiddlewareExtensionsTests/SlowDownOptionsTests * Make many of the middleware integration tests work again * [WIP] Attempting to force a 404 * Fix more tests * Remove `AspNetTestServerFixture`, not used * Make /err work! * Address some static analysis finds * Get back to 100% code coverage on AspNetCoreHelper * Static analysis fix * Allow an IP to be passed to CreateXForwardedForHttpRequest() * Suppress an unused warning * Add tests for `CacheHelper`'s `Remove()` and `RemoveAll()` * Remove dead code * Remove the `TimeDelay` check in `CalculateDelay()` A window of 0 is invalid for HybridCache and causes an exception. * Get the middleware back to 100% test coverage. * Static analysis fix * Be consistent * Set the URLs to the Nearform repo * s/Nearform/Nearform Ltd. * Add the README to the generated NuGet package * Remove dead code * Fix some issues in the readme * Add Authors/Company/Copyright to the rest of the project files
- Loading branch information
Showing
57 changed files
with
1,832 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=BasicSlowDownExample_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=extexp/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=mundo/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=nearform/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...tributedCacheSlowDownExample.ApiService/DistributedCacheSlowDownExample.ApiService.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<Authors>Ross Nelson</Authors> | ||
<Company>Nearform Ltd.</Company> | ||
<Copyright>Copyright (C) 2024 Nearform Ltd.</Copyright> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\SlowDown\Nearform.AspNetCore.SlowDown.csproj" /> | ||
<ProjectReference Include="..\DistributedCacheSlowDownExample.ServiceDefaults\DistributedCacheSlowDownExample.ServiceDefaults.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Aspire.StackExchange.Redis.DistributedCaching" Version="9.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
54 changes: 54 additions & 0 deletions
54
...les/DistributedCacheSlowDownExample/DistributedCacheSlowDownExample.ApiService/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Nearform.AspNetCore.SlowDown; | ||
// ReSharper disable HeapView.ObjectAllocation | ||
// ReSharper disable HeapView.ObjectAllocation.Evident | ||
// ReSharper disable HeapView.DelegateAllocation | ||
// ReSharper disable HeapView.ClosureAllocation | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add service defaults & Aspire components. | ||
builder.AddServiceDefaults(); | ||
|
||
// Use the Aspire Redis connection | ||
builder.AddRedisClient(connectionName: "cache"); | ||
builder.AddRedisDistributedCache(connectionName: "cache"); | ||
|
||
// Add services to the container. | ||
builder.Services.AddProblemDetails(); | ||
|
||
var app = builder.Build(); | ||
|
||
app.UseSlowDown(); | ||
|
||
// Configure the HTTP request pipeline. | ||
app.UseExceptionHandler(); | ||
|
||
var summaries = new[] | ||
{ | ||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
}; | ||
|
||
app.MapGet("/weatherforecast", () => | ||
{ | ||
var forecast = Enumerable.Range(1, 5).Select( index => | ||
new WeatherForecast | ||
( | ||
DateOnly.FromDateTime(DateTime.Now.AddDays(index)), | ||
Random.Shared.Next(-20, 55), | ||
summaries[Random.Shared.Next(summaries.Length)] | ||
)) | ||
.ToArray(); | ||
return forecast; | ||
}); | ||
|
||
app.MapDefaultEndpoints(); | ||
|
||
app.Run(); | ||
|
||
[SuppressMessage("ReSharper", "NotAccessedPositionalProperty.Global")] | ||
[SuppressMessage("ReSharper", "UnusedMember.Global")] | ||
internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary) | ||
{ | ||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
} |
25 changes: 25 additions & 0 deletions
25
...SlowDownExample/DistributedCacheSlowDownExample.ApiService/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "weatherforecast", | ||
"applicationUrl": "http://localhost:5556", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "weatherforecast", | ||
"applicationUrl": "https://localhost:7345;http://localhost:5556", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...heSlowDownExample/DistributedCacheSlowDownExample.ApiService/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...stributedCacheSlowDownExample/DistributedCacheSlowDownExample.ApiService/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"SlowDown": { | ||
"Delay": 5000, | ||
"DelayAfter": 50, | ||
"MaxDelay": 30000, | ||
"TimeWindow": 600000, | ||
"CacheTimeout": 2147483646 | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ibutedCacheSlowDownExample.ApiService2/DistributedCacheSlowDownExample.ApiService2.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Authors>Ross Nelson</Authors> | ||
<Company>Nearform Ltd.</Company> | ||
<Copyright>Copyright (C) 2024 Nearform Ltd.</Copyright> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\SlowDown\Nearform.AspNetCore.SlowDown.csproj" /> | ||
<ProjectReference Include="..\DistributedCacheSlowDownExample.ServiceDefaults\DistributedCacheSlowDownExample.ServiceDefaults.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Aspire.StackExchange.Redis.DistributedCaching" Version="9.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
54 changes: 54 additions & 0 deletions
54
...es/DistributedCacheSlowDownExample/DistributedCacheSlowDownExample.ApiService2/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Nearform.AspNetCore.SlowDown; | ||
// ReSharper disable HeapView.ObjectAllocation | ||
// ReSharper disable HeapView.ObjectAllocation.Evident | ||
// ReSharper disable HeapView.DelegateAllocation | ||
// ReSharper disable HeapView.ClosureAllocation | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add service defaults & Aspire components. | ||
builder.AddServiceDefaults(); | ||
|
||
// Use the Aspire Redis connection | ||
builder.AddRedisClient(connectionName: "cache"); | ||
builder.AddRedisDistributedCache(connectionName: "cache"); | ||
|
||
// Add services to the container. | ||
builder.Services.AddProblemDetails(); | ||
|
||
var app = builder.Build(); | ||
|
||
app.UseSlowDown(); | ||
|
||
// Configure the HTTP request pipeline. | ||
app.UseExceptionHandler(); | ||
|
||
var summaries = new[] | ||
{ | ||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
}; | ||
|
||
app.MapGet("/weatherforecast", () => | ||
{ | ||
var forecast = Enumerable.Range(1, 5).Select(index => | ||
new WeatherForecast | ||
( | ||
DateOnly.FromDateTime(DateTime.Now.AddDays(index)), | ||
Random.Shared.Next(-20, 55), | ||
summaries[Random.Shared.Next(summaries.Length)] | ||
)) | ||
.ToArray(); | ||
return forecast; | ||
}); | ||
|
||
app.MapDefaultEndpoints(); | ||
|
||
app.Run(); | ||
|
||
[SuppressMessage("ReSharper", "NotAccessedPositionalProperty.Global")] | ||
[SuppressMessage("ReSharper", "UnusedMember.Global")] | ||
internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary) | ||
{ | ||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
} |
15 changes: 15 additions & 0 deletions
15
...lowDownExample/DistributedCacheSlowDownExample.ApiService2/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "weatherforecast", | ||
"applicationUrl": "http://localhost:5249", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...eSlowDownExample/DistributedCacheSlowDownExample.ApiService2/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...tributedCacheSlowDownExample/DistributedCacheSlowDownExample.ApiService2/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"SlowDown": { | ||
"Delay": 5000, | ||
"DelayAfter": 50, | ||
"MaxDelay": 30000, | ||
"TimeWindow": 600000, | ||
"CacheTimeout": 2147483646 | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...le/DistributedCacheSlowDownExample.AppHost/DistributedCacheSlowDownExample.AppHost.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<Authors>Ross Nelson</Authors> | ||
<Company>Nearform Ltd.</Company> | ||
<Copyright>Copyright (C) 2024 Nearform Ltd.</Copyright> | ||
<IsAspireHost>true</IsAspireHost> | ||
<UserSecretsId>5aa6c716-9fce-49bb-a0d4-fa4aacc36b22</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" /> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\DistributedCacheSlowDownExample.ApiService2\DistributedCacheSlowDownExample.ApiService2.csproj" /> | ||
<ProjectReference Include="..\DistributedCacheSlowDownExample.ApiService\DistributedCacheSlowDownExample.ApiService.csproj" /> | ||
<ProjectReference Include="..\DistributedCacheSlowDownExample.Web\DistributedCacheSlowDownExample.Web.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.0.0" /> | ||
<PackageReference Include="Aspire.Hosting.Redis" Version="9.0.0" /> | ||
<PackageReference Include="Aspire.StackExchange.Redis.DistributedCaching" Version="9.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Caching.Hybrid" Version="9.0.0-preview.9.24556.5" /> | ||
</ItemGroup> | ||
|
||
</Project> |
22 changes: 22 additions & 0 deletions
22
samples/DistributedCacheSlowDownExample/DistributedCacheSlowDownExample.AppHost/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// ReSharper disable InconsistentNaming | ||
|
||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var cache = builder.AddRedis("cache") | ||
.WithRedisInsight() | ||
.WithRedisCommander(); | ||
|
||
var api1_5556 = builder | ||
.AddProject<Projects.DistributedCacheSlowDownExample_ApiService>("api1-5556") | ||
.WithReference(cache); | ||
var api2_5249 = builder | ||
.AddProject<Projects.DistributedCacheSlowDownExample_ApiService2>("api2-5249") | ||
.WithReference(cache); | ||
|
||
builder.AddProject<Projects.DistributedCacheSlowDownExample_Web>("web") | ||
.WithExternalHttpEndpoints() | ||
.WithReference(cache) | ||
.WithReference(api1_5556) | ||
.WithReference(api2_5249); | ||
|
||
builder.Build().Run(); |
29 changes: 29 additions & 0 deletions
29
...cheSlowDownExample/DistributedCacheSlowDownExample.AppHost/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "https://localhost:17124;http://localhost:15260", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"DOTNET_ENVIRONMENT": "Development", | ||
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21006", | ||
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22279" | ||
} | ||
}, | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "http://localhost:15260", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"DOTNET_ENVIRONMENT": "Development", | ||
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19059", | ||
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20228" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.