Eiffel
  • Overview
    • About
  • Features
    • Cross cutting concerns
      • API response consistency
      • Global exception handling
      • Idempotency
      • Audit logging
    • Caching
      • Configuration
        • In-Memory
        • Redis
      • Usage
      • API
        • CacheSource
        • InMemoryCacheOptions
        • RedisCacheOptions
        • ICacheService
        • ICacheServiceFactory
    • Localization
    • Job Processing
    • Multi-Tenancy
    • Metrics & monitoring
    • Transactional outbox
      • PostgreSQL
      • MongoDB (cluster only)
    • Messaging
      • Kafka
      • Rabbit MQ
      • Azure Service Bus
    • Awaitable socket client
    • Graceful shutdown
  • Fundamentals
    • Persistence
    • Modelling
  • Principles
    • Domain-Driven Design
      • Aggregates
      • Entities
      • Value Objects
      • Domain Events
      • Factories
      • Domain Services
      • Business Identifiers
      • Shared Kernel
    • Onion Architecture
      • Application Layer
      • Domain Layer
      • Infrastructure Layer
      • Anti-Corruption Layer
    • Modular Monolith Architecture
      • Modules
      • Shared Infrastructure
    • Microservice Architecture
      • API Gateway
      • View Model Composition
      • Contracts
  • Business Aligment
    • Domain Storytelling
    • User stories
  • Implementation
    • Modular Monolith
    • Microservices
  • Testing
    • Unit Testing
    • Integration Testing
    • Contract Testing
  • Cloud Infrastructure
    • CI/CD Pipelines
    • Docker
    • Kubernates
    • Infrastructure as Code
Powered by GitBook
On this page
  1. Features
  2. Caching
  3. Configuration

In-Memory

PreviousConfigurationNextRedis

Last updated 1 year ago

In-Memory cache provides own configuration properties. For configuration details please .

You can configure values from appsettings.json file

{
    "Caching": {
        "Source": "InMemory",
        "InMemory": {
           "TrackStatistics": true,
           "ExpirationScanFrequencyInSeconds" : 30
        }
    }
}

If you need to advanced configuration or configure cache service without appsettings.json file. You can use extension method.

AddCaching method initally read values from appsettings.json file afterwards applies configuration from action method.

// Program.cs (.NET5 and above)
public static async Task Main(string[] args)
{
    var builder = WebApplication.CreateBuilder(args);
    
    // Add with configuration instance
    var cacheOptions = new InMemoryCacheOptions();
    cacheOptions.ExpirationScanFrequencyInSeconds = 30;
    cacheOptions.Clock = new CustomSystemClock(); // Your custom ISystemClock implementation.
    builder.AddCaching(x => x.InMemory(cacheOptions));

    // Add with inline action method
    builder.AddCaching(x => x.InMemory(x => x.ExpirationScanFrequencyInSeconds = 120));
 
    var app = builder.Build();
    app.Run();
}
visit