Configuration

Caching module requires serveral NuGet package installations. First you need to install Eiffel.Caching.Extensions.DependencyInjection package.

dotnet add package Eiffel.Caching.Extensions.DependencyInjection

After the installation, AddCaching extension method will be accessible from WebApplicationBuilder class instance.

The Caching module provides distributed and in-memory caching options. The CacheSource enum provides a list of supported cache sources

You can use the AddCaching method without parameters, but in that case, you must define the Caching section with the related source configuration in the appsettings.json file.

// Program.cs (.NET5 and above)
public static async Task Main(string[] args)
{
    var builder = WebApplication.CreateBuilder(args);
    
    // Add caching
    builder.AddCaching();
     
    var app = builder.Build();
    app.Run();
}

Example Redis configuration section. For configuration details please read.

{
    "Caching": {
        "Source": "Redis",
        "Redis": {
            ... // Put your redis configuration values here
        }
    }
}

Example In-Memory configuration section. For configuration details please read.

{
    "Caching": {
        "Source": "InMemory",
        "InMemory": {
            ... // Put your in-memory configuration values here
        }
    }
}

Last updated