diff --git a/.gitignore b/.gitignore index ef951f5..12364bf 100644 --- a/.gitignore +++ b/.gitignore @@ -399,3 +399,5 @@ FodyWeavers.xsd .DS_Store k8s/sp.sh .vscode/settings.json + +.idea/ \ No newline at end of file diff --git a/README.md b/README.md index 576a332..81ca44d 100644 --- a/README.md +++ b/README.md @@ -9,15 +9,15 @@ Nebula.Caching is an Open-Source caching library that allows you to use caching in your projects with minimal configuration. -As of today, we support caching using Redis and InMemory, but in the future we hope to support your favourite caching provider! +As of today, we support caching using Redis, InMemory and Memcached, but in the future we hope to support your favourite caching provider! ## Nuget Package | Name | Released Package | | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Nebula-Caching-Redis | [![BotBuilder Badge](https://buildstats.info/nuget/Nebula-Caching-Redis?includePreReleases=true&dWidth=70)](https://www.nuget.org/packages/Nebula-Caching-Redis/) | -| Nebula-Caching-InMemory | [![BotBuilder Badge](https://buildstats.info/nuget/Nebula-Caching-InMemory?includePreReleases=true&dWidth=70)](https://www.nuget.org/packages/Nebula-Caching-InMemory/) | -| Nebula-Caching-Memcached | [![BotBuilder Badge](https://buildstats.info/nuget/Nebula-Caching-Memcached?includePreReleases=true&dWidth=70)](https://www.nuget.org/packages/Nebula-Caching-Memcached/) | +| NebulaCaching.Redis | [![BotBuilder Badge](https://buildstats.info/nuget/NebulaCaching.Redis?includePreReleases=true&dWidth=70)](https://www.nuget.org/packages/Caching.Nebula.Redis/) | +| NebulaCaching.InMemory | [![BotBuilder Badge](https://buildstats.info/nuget/NebulaCaching.InMemory?includePreReleases=true&dWidth=70)](https://www.nuget.org/packages/Caching.Nebula.InMemory) | +| NebulaCaching.Memcached | [![BotBuilder Badge](https://buildstats.info/nuget/NebulaCaching.Memcached?includePreReleases=true&dWidth=70)](https://www.nuget.org/packages/Caching.Nebula.Memcached/) | ## Usage @@ -26,9 +26,9 @@ As of today, we support caching using Redis and InMemory, but in the future we h Install the package via Package Manager: ``` -Install-Package Nebula-Caching-Redis -Install-Package Nebula-Caching-InMemory -Install-Package Nebula-Caching-Memcached +Install-Package NebulaCaching.Redis +Install-Package NebulaCaching.InMemory +Install-Package NebulaCaching.Memcached ``` or @@ -36,9 +36,9 @@ or Via .NET CLI: ``` -dotnet add package Nebula-Caching-Redis -dotnet add package Nebula-Caching-InMemory -dotnet add package Nebula-Caching-Memcached +dotnet add package NebulaCaching.Redis +dotnet add package NebulaCaching.InMemory +dotnet add package NebulaCaching.Memcached ``` ### Step 2 : Register cache usage in the Program class (will change depending on which caching provider you are using, please refer to the package documentation) @@ -52,7 +52,7 @@ public class Program // ... builder.Host.UseNebulaCaching(); - builder.Services.AddRedisChache(new Configurations + builder.Services.AddRedisChache(new RedisConfigurations { //some amazing configuration options which can be see in the samples or documentation section }); diff --git a/docs/documentation/Redis/AttributeUsage/AttributeUsage.md b/docs/documentation/Redis/AttributeUsage/AttributeUsage.md index 976dd6d..aa056e3 100644 --- a/docs/documentation/Redis/AttributeUsage/AttributeUsage.md +++ b/docs/documentation/Redis/AttributeUsage/AttributeUsage.md @@ -79,7 +79,7 @@ Let's take a closer look at the structure of the second configuration cache key //this is the key we are analyzing Gorold-Payment-Attributes-RedisStuff--SomeMethod--{param1}--{param2}--{name} -Gorold-Payment-Attributes-RedisStuff -> Namespace where the interface, where the attribute was placed, implementation is located. Notice that we replaced all the '.' for '-'. +Gorold-Payment-Attributes-RedisStuff -> Namespace where the interface, on which the attributes were placed, implementation is located. Notice that we replaced all the namespace '.' for '-'. --SomeMethod--{param1}--{param2}--{name} -> The remaining part of the key is constitued of the method where the attribute was placed, plus the methods it might contain. If no parameters exist, then we don't need to insert them on the cache key definition. If you notice closely, when you are adding cache duration for methods that take parameters, you must add such parameters inside the curly braces. You should add only the parameter name, not its value. Also notice that, unline above, we use double '-' to separate things. ``` @@ -153,7 +153,7 @@ An example of that can be seen below: ```json "Redis": { - "CacheGroupSettings": { + "CacheSettings": { "MyCustomCacheName" : "04:00:00" } } diff --git a/docs/documentation/Redis/CacheRegistration/CacheRegistration.md b/docs/documentation/Redis/CacheRegistration/CacheRegistration.md index 2cd064a..9b11508 100644 --- a/docs/documentation/Redis/CacheRegistration/CacheRegistration.md +++ b/docs/documentation/Redis/CacheRegistration/CacheRegistration.md @@ -11,7 +11,7 @@ public class Program // ... builder.Host.UseNebulaCaching(); - builder.Services.AddRedisChache(new Configurations + builder.Services.AddRedisChache(new RedisConfigurations { //some amazing configuration options }); @@ -112,7 +112,7 @@ public class Program { // ... builder.Host.UseNebulaCaching(); - builder.Services.AddRedisChache(new Configurations + builder.Services.AddRedisChache(new RedisConfigurations { ConfigurationSection = "RedisConfig", ConfigurationFlavour = RedisConfigurationFlavour.Vanilla, diff --git a/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample.sln b/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample.sln new file mode 100644 index 0000000..7858fe1 --- /dev/null +++ b/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nebula.Caching.InMemorySample", "Nebula.Caching.InMemorySample\Nebula.Caching.InMemorySample.csproj", "{C0DBA380-6D13-4E31-8662-2897207F3AB0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C0DBA380-6D13-4E31-8662-2897207F3AB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C0DBA380-6D13-4E31-8662-2897207F3AB0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C0DBA380-6D13-4E31-8662-2897207F3AB0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C0DBA380-6D13-4E31-8662-2897207F3AB0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/Controllers/WeatherForecastController.cs b/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..c353fd9 --- /dev/null +++ b/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/Controllers/WeatherForecastController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Nebula.Caching.InMemorySample.Controllers; + +[ApiController] +[Route("[controller]")] +public class WeatherForecastController : ControllerBase +{ + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } +} \ No newline at end of file diff --git a/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample.csproj b/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample.csproj new file mode 100644 index 0000000..1b490bf --- /dev/null +++ b/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample.csproj @@ -0,0 +1,14 @@ + + + + net7.0 + enable + enable + + + + + + + + diff --git a/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/Program.cs b/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/Program.cs new file mode 100644 index 0000000..8264bac --- /dev/null +++ b/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/Program.cs @@ -0,0 +1,25 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); \ No newline at end of file diff --git a/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/Properties/launchSettings.json b/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/Properties/launchSettings.json new file mode 100644 index 0000000..38f52b1 --- /dev/null +++ b/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:18977", + "sslPort": 44367 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5029", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7101;http://localhost:5029", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/WeatherForecast.cs b/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/WeatherForecast.cs new file mode 100644 index 0000000..7ef091b --- /dev/null +++ b/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/WeatherForecast.cs @@ -0,0 +1,12 @@ +namespace Nebula.Caching.InMemorySample; + +public class WeatherForecast +{ + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } +} \ No newline at end of file diff --git a/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/appsettings.Development.json b/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/appsettings.json b/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/docs/samples/InMemory/Nebula.Caching.InMemorySample/Nebula.Caching.InMemorySample/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample.sln b/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample.sln new file mode 100644 index 0000000..9c6ddc6 --- /dev/null +++ b/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nebula.Caching.MemcachedSample", "Nebula.Caching.MemcachedSample\Nebula.Caching.MemcachedSample.csproj", "{2A8CC86B-2D17-4890-AFD2-BC67ACECF6CB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2A8CC86B-2D17-4890-AFD2-BC67ACECF6CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2A8CC86B-2D17-4890-AFD2-BC67ACECF6CB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2A8CC86B-2D17-4890-AFD2-BC67ACECF6CB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2A8CC86B-2D17-4890-AFD2-BC67ACECF6CB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/Controllers/WeatherForecastController.cs b/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..ac0846e --- /dev/null +++ b/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/Controllers/WeatherForecastController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Nebula.Caching.MemcachedSample.Controllers; + +[ApiController] +[Route("[controller]")] +public class WeatherForecastController : ControllerBase +{ + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } +} \ No newline at end of file diff --git a/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample.csproj b/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample.csproj new file mode 100644 index 0000000..1b490bf --- /dev/null +++ b/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample.csproj @@ -0,0 +1,14 @@ + + + + net7.0 + enable + enable + + + + + + + + diff --git a/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/Program.cs b/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/Program.cs new file mode 100644 index 0000000..8264bac --- /dev/null +++ b/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/Program.cs @@ -0,0 +1,25 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); \ No newline at end of file diff --git a/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/Properties/launchSettings.json b/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/Properties/launchSettings.json new file mode 100644 index 0000000..a89b302 --- /dev/null +++ b/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:5677", + "sslPort": 44339 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5272", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7137;http://localhost:5272", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/WeatherForecast.cs b/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/WeatherForecast.cs new file mode 100644 index 0000000..50a97ff --- /dev/null +++ b/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/WeatherForecast.cs @@ -0,0 +1,12 @@ +namespace Nebula.Caching.MemcachedSample; + +public class WeatherForecast +{ + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } +} \ No newline at end of file diff --git a/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/appsettings.Development.json b/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/appsettings.json b/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/docs/samples/Memcached/Nebula.Caching.MemcachedSample/Nebula.Caching.MemcachedSample/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample.sln b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample.sln new file mode 100644 index 0000000..31eb799 --- /dev/null +++ b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nebula.Caching.RedisSample", "Nebula.Caching.RedisSample\Nebula.Caching.RedisSample.csproj", "{01429980-0772-48B4-A103-6282A23137B6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {01429980-0772-48B4-A103-6282A23137B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {01429980-0772-48B4-A103-6282A23137B6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {01429980-0772-48B4-A103-6282A23137B6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {01429980-0772-48B4-A103-6282A23137B6}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Controllers/WeatherForecastController.cs b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..9d7ab9a --- /dev/null +++ b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Controllers/WeatherForecastController.cs @@ -0,0 +1,41 @@ +using Microsoft.AspNetCore.Mvc; +using Nebula.Caching.RedisSample.Interfaces; + +namespace Nebula.Caching.RedisSample.Controllers; + +[ApiController] +[Route("[controller]")] +public class WeatherForecastController : ControllerBase +{ + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + private readonly IService _service; + + public WeatherForecastController(ILogger logger, IService service) + { + _logger = logger; + _service = service; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + _service.MagicMethod(); + _service.AnotherMethod("Rafael"); + _service.OneMethod("Rafael", 1996); + _service.SomeMethod(); + + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } +} \ No newline at end of file diff --git a/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Interfaces/IService.cs b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Interfaces/IService.cs new file mode 100644 index 0000000..febedcd --- /dev/null +++ b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Interfaces/IService.cs @@ -0,0 +1,29 @@ +using Nebula.Caching.Redis.Attributes; + +namespace Nebula.Caching.RedisSample.Interfaces; + +public interface IService +{ + //this method will use the cache duration from settings.json config file + [RedisCache] + string OneMethod(string name, int year); + + //this method will use the cache duration defined in the settings.json config file, not the default cache duration + //uses custom name + [RedisCache(CustomCacheName = "MagicName")] + int MagicMethod(); + + //this method will use the cache duration defined on the constructor + [RedisCache(CacheDurationInSeconds = 120)] + ComplexObject AnotherMethod(string someParameter); + + //this method will use the cache duration defined for this cache group on our settings.json config file + [RedisCache(CacheGroup = "GroupA")] + bool SomeMethod(); +} + +public class ComplexObject +{ + public string Name { get; set; } = string.Empty; + public int Age { get; set; } +} \ No newline at end of file diff --git a/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample.csproj b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample.csproj new file mode 100644 index 0000000..6fd9eb3 --- /dev/null +++ b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample.csproj @@ -0,0 +1,15 @@ + + + + net7.0 + enable + enable + + + + + + + + + diff --git a/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Program.cs b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Program.cs new file mode 100644 index 0000000..643a7e2 --- /dev/null +++ b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Program.cs @@ -0,0 +1,46 @@ +using Nebula.Caching.Common.Extensions; +using Nebula.Caching.Redis.Extensions; +using Nebula.Caching.Redis.Settings; +using Nebula.Caching.RedisSample.Interfaces; +using Nebula.Caching.RedisSample.Services; +using Redis.Settings; + +public class Program +{ + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + + // Start cache configuration + builder.Host.UseNebulaCaching(); + builder.Services.AddRedisChache(new RedisConfigurations + { + DefaultCacheDurationInSeconds = 3600, + ConfigurationFlavour = RedisConfigurationFlavour.Vanilla, + ConfigurationSection = "RedisConfig" + }); + // End cache configuration + + builder.Services.AddScoped(); + + builder.Services.AddControllers(); + builder.Services.AddEndpointsApiExplorer(); + builder.Services.AddSwaggerGen(); + + var app = builder.Build(); + + if (app.Environment.IsDevelopment()) + { + app.UseSwagger(); + app.UseSwaggerUI(); + } + + app.UseHttpsRedirection(); + + app.UseAuthorization(); + + app.MapControllers(); + + app.Run(); + } +} \ No newline at end of file diff --git a/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Properties/launchSettings.json b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Properties/launchSettings.json new file mode 100644 index 0000000..3a0a7b1 --- /dev/null +++ b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:37945", + "sslPort": 44380 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5269", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7278;http://localhost:5269", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Services/ServiceImplementation.cs b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Services/ServiceImplementation.cs new file mode 100644 index 0000000..ba9da73 --- /dev/null +++ b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/Services/ServiceImplementation.cs @@ -0,0 +1,30 @@ +using Nebula.Caching.RedisSample.Interfaces; + +namespace Nebula.Caching.RedisSample.Services; + +public class ServiceImplementation : IService +{ + public string OneMethod(string name, int year) + { + return $"{name} was born in {year}."; + } + + public int MagicMethod() + { + return 2023; + } + + public ComplexObject AnotherMethod(string someParameter) + { + return new ComplexObject + { + Age = 2023, + Name = someParameter + }; + } + + public bool SomeMethod() + { + return false; + } +} \ No newline at end of file diff --git a/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/WeatherForecast.cs b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/WeatherForecast.cs new file mode 100644 index 0000000..4c40a67 --- /dev/null +++ b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/WeatherForecast.cs @@ -0,0 +1,12 @@ +namespace Nebula.Caching.RedisSample; + +public class WeatherForecast +{ + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } +} \ No newline at end of file diff --git a/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/appsettings.Development.json b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/appsettings.Development.json new file mode 100644 index 0000000..f1b443f --- /dev/null +++ b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/appsettings.Development.json @@ -0,0 +1,18 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "RedisConfig" : { + "CacheServiceUrl" : "localhost", + "CacheSettings": { + "MagicName" : "04:00:00", + "Nebula-Caching-RedisSample-Services--OneMethod--{name}--{year}" : "01:02:03" + }, + "CacheGroupSettings": { + "GroupA" : "02:23:15" + } + } +} diff --git a/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/appsettings.json b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/docs/samples/Redis/Nebula.Caching.RedisSample/Nebula.Caching.RedisSample/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/docs/samples/Redis/Samples.md b/docs/samples/Redis/Samples.md deleted file mode 100644 index d779e20..0000000 --- a/docs/samples/Redis/Samples.md +++ /dev/null @@ -1,77 +0,0 @@ -# Code samples - -### Using the simple configuration scenario (_Vanilla_), with a default cache duration of 120 seconds, and the cache configuration in appsettings.json will occur in the section _RedisConfig_ - -```csharp - -public class Program -{ - public static void Main(string[] args) - { - // ... - builder.Host.UseNebulaCaching(); - builder.Services.AddRedisChache(new Configurations - { - ConfigurationSection = "RedisConfig", - ConfigurationFlavour = RedisConfigurationFlavour.Vanilla, - DefaultCacheDurationInSeconds = 120 - }); - } -} - -``` - -The _appsettings.json_ file should have the configured section: - -```json - "RedisConfig": { - "CacheServiceUrl": "localhost", - "CacheSettings": { - //whatver cache keys are configured with respective cache duration - } - } -``` - -### Redis configuration is managed by the library user, with a default cache duration of 50 seconds, and the cache configuration in appsettings.json will occur in the section _MyCacheConfigSection_ - -```csharp - -public class Program -{ - public static void Main(string[] args) - { - // ... - - //since managing Redis is not done by the library, we must have *IConnectionMultiplexer* injected for the library to properly work - builder.Services.AddSingleton(ctx => - { - return ConnectionMultiplexer.Connect(""); - }); - builder.Host.UseNebulaCaching(); - builder.Services.AddRedisChache(new Configurations - { - ConfigurationSection = "MyCacheConfigSection", - DefaultCacheDurationInSeconds = 50 - }); - } -} - -``` - -The _appsettings.json_ file should have the configured section: - -```json - "MyCacheConfigSection": { - "CacheSettings": { - //whatver cache keys are configured with respective cache duration - } - } -``` - -### After configuring your application with any of the configurations above, you start configuring your attributes to use cache - -Please check [this documentation file](../documentation/AttributeUsage/AttributeUsage.md) to have a lot of samples and use cases about some variety of attribute configurations. - -### Project that uses Nebula.Caching - -Please check [this project](https://github.com/Gorold-Streaming-Services/Gorold.Payment/blob/main/Gorold.Payment/Program.cs) for a real use case of our caching solution. diff --git a/src/Nebula.Caching.Common/Nebula.Caching.Common.csproj b/src/Nebula.Caching.Common/Nebula.Caching.Common.csproj index d8f956c..e481acd 100644 --- a/src/Nebula.Caching.Common/Nebula.Caching.Common.csproj +++ b/src/Nebula.Caching.Common/Nebula.Caching.Common.csproj @@ -4,6 +4,14 @@ net6.0 enable enable + NebulaCaching.Common + 0.1.0 + Rafael Camara + Nebula Software Systems + Make your dotnet core apps shine by using caching without cluttering your projects. + MIT + Cache, Caching, Common Abstractions + https://github.com/Nebula-Software-Systems/Nebula.Caching diff --git a/src/Nebula.Caching.InMemory/Nebula.Caching.InMemory.csproj b/src/Nebula.Caching.InMemory/Nebula.Caching.InMemory.csproj index 693fc55..6f3bed7 100644 --- a/src/Nebula.Caching.InMemory/Nebula.Caching.InMemory.csproj +++ b/src/Nebula.Caching.InMemory/Nebula.Caching.InMemory.csproj @@ -4,8 +4,8 @@ net6.0 enable enable - Nebula-Caching-InMemory - 1.0.1 + NebulaCaching.InMemory + 0.1.0 Rafael Camara Nebula Software Systems Make your dotnet core apps shine by using caching without cluttering your projects. @@ -13,13 +13,10 @@ Cache, Caching, InMemory https://github.com/Nebula-Software-Systems/Nebula.Caching - - - - - + + diff --git a/src/Nebula.Caching.Memcached/Nebula.Caching.Memcached.csproj b/src/Nebula.Caching.Memcached/Nebula.Caching.Memcached.csproj index 5eec3fa..1fd6976 100644 --- a/src/Nebula.Caching.Memcached/Nebula.Caching.Memcached.csproj +++ b/src/Nebula.Caching.Memcached/Nebula.Caching.Memcached.csproj @@ -4,8 +4,8 @@ net6.0 enable enable - Nebula-Caching-Memcached - 1.0.0 + NebulaCaching.Memcached + 0.1.0 Rafael Camara Nebula Software Systems Make your dotnet core apps shine by using caching without cluttering your projects. @@ -17,10 +17,7 @@ - - - - + diff --git a/src/Nebula.Caching.Redis/Nebula.Caching.Redis.csproj b/src/Nebula.Caching.Redis/Nebula.Caching.Redis.csproj index 50cab8d..6b5ea4b 100644 --- a/src/Nebula.Caching.Redis/Nebula.Caching.Redis.csproj +++ b/src/Nebula.Caching.Redis/Nebula.Caching.Redis.csproj @@ -4,8 +4,8 @@ net6.0 enable enable - Nebula-Caching-Redis - 1.0.0 + NebulaCaching.Redis + 0.1.0 Rafael Camara Nebula Software Systems Make your dotnet core apps shine by using caching without cluttering your projects. @@ -14,13 +14,18 @@ https://github.com/Nebula-Software-Systems/Nebula.Caching + + + + + - + - +