# kevindockx/httpcacheheaders architecture

> Architecture diagram of the GitHub repository kevindockx/httpcacheheaders, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kevindockx/httpcacheheaders
- Repository: https://github.com/kevindockx/httpcacheheaders

## Overview

##### Project type and purpose
- This is an open-source ASP.NET Core “middleware” library that generates and validates HTTP cache headers (Cache-Control, Expires, ETag, Last-Modified) but does not itself store response payloads.
- It provides core functionality in the Marvin.Cache.Headers project, an optional distributed store abstraction (Marvin.Cache.Headers.DistributedStore) and a Redis-backed implementation (Marvin.Cache.Headers.DistributedStore.Redis).
- A sample ASP.NET Core app under `sample/Marvin.Cache.Headers.Sample` demonstrates usage; multiple `test/…` projects cover unit tests for each component.

##### File structure
- Top-level solution files (`.sln`), NuGet config and build scripts.
- `src/Marvin.Cache.Headers`: core middleware, attributes, interfaces, default implementations (in–memory store, default generators/injectors/parsers).
- `src/Marvin.Cache.Headers.DistributedStore`: abstraction over IValidatorValueStore and IStoreKeyGenerator.
- `src/Marvin.Cache.Headers.DistributedStore.Redis`: Redis extension implementing the distributed store interface.
- `sample/Marvin.Cache.Headers.Sample`: a minimal ASP.NET Core Web API with controllers, Program.cs, appsettings.json.
- `test/…`: a test project for each library, verifying extension methods, store behaviors, ETag injection, serialization, etc.

##### README for additional insights
- Confirms the middleware must be added between `UseRouting()` and `UseEndpoints()`.
- Describes configuration points: expiration/validation model options, middleware options.
- Lists extensibility points: IValidatorValueStore, IStoreKeyGenerator, IETagGenerator, IETagInjector, ILastModifiedInjector, IDateParser, IValidatorValueInvalidator, IStoreKeyAccessor.

##### Detail and essential architectural elements
- How middleware options (expirationModelOptions, validationModelOptions, middlewareOptions) flow into the Middleware component.
- Redis distributed store module is shown as an optional plugin that replaces the in-memory store.

## Diagram (Mermaid)

```mermaid
flowchart TB
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef store fill:#90EE90,stroke:#000,stroke-width:1px
    classDef ext fill:#FFA500,stroke:#000,stroke-width:1px
    classDef app fill:#FFD700,stroke:#000,stroke-width:1px

    Client["Client (HTTP Consumer)"]:::app
    subgraph "ASP.NET Core Host"
        direction TB
        UseRouting["1. UseRouting()"]:::core
        CacheMiddleware["2. UseHttpCacheHeaders()"]:::core
        UseEndpoints["3. UseEndpoints()"]:::core
    end
    Client -->|Request| UseRouting
    UseRouting -->|Forward| CacheMiddleware
    CacheMiddleware -->|Forward| UseEndpoints
    UseEndpoints --> Controllers
    Controllers["MVC Controllers"]:::app
    Controllers -->|Produces Response| CacheMiddleware
    CacheMiddleware -->|Response| Client

    subgraph "Core Library: Marvin.Cache.Headers"
        direction TB
        HttpCacheHeadersMiddleware["HttpCacheHeadersMiddleware"]:::core
        StoreKeyGen["DefaultStoreKeyGenerator"]:::core
        Interfaces["Interfaces (IValidatorValueStore, IStoreKeyGenerator, IValidatorValueInvalidator, IStoreKeyAccessor, IDateParser, IETagGenerator, IETagInjector, ILastModifiedInjector)"]:::ext
        InMemoryStore["InMemoryValidatorValueStore"]:::store
        Serializer["DefaultStoreKeySerializer"]:::core
        ETagGen["DefaultStrongETagGenerator"]:::core
        ETagInj["DefaultETagInjector"]:::core
        LastModInj["DefaultLastModifiedInjector"]:::core
        DateParser["DefaultDateParser"]:::core
        StoreKeyAcc["StoreKeyAccessor"]:::core
        ValidatorInv["ValidatorValueInvalidator"]:::core
        Domain["Domain Models & Options"]:::core
    end

    CacheMiddleware -->|uses| HttpCacheHeadersMiddleware
    HttpCacheHeadersMiddleware -->|generates key| StoreKeyGen
    StoreKeyGen -->|calls| Interfaces
    Interfaces -->|default| InMemoryStore
    InMemoryStore -->|serializes key| Serializer
    HttpCacheHeadersMiddleware -->|on response| ETagGen
    ETagGen -->|injects| ETagInj
    ETagInj -->|injects| LastModInj
    LastModInj -->|uses| DateParser
    HttpCacheHeadersMiddleware -->|invalidates| ValidatorInv
    ValidatorInv -->|accessor| StoreKeyAcc
    HttpCacheHeadersMiddleware -->|models| Domain

    subgraph "Distributed Store Abstraction"
        direction TB
        DistInterfaces["IRetrieveDistributedCacheKeys"]:::ext
        DistributedStore["DistributedCacheValidatorValueStore"]:::store
    end
    Interfaces -->|alternative| DistributedStore
    DistributedStore -->|uses| DistInterfaces

    subgraph "Redis Implementation"
        direction TB
        RedisExt["ServicesExtensions (Redis)"]:::ext
        RedisOptions["RedisDistributedCacheKeyRetrieverOptions"]:::ext
        RedisRetriever["RedisDistributedCacheKeyRetriever"]:::store
    end
    DistInterfaces --> RedisRetriever
    RedisRetriever --> RedisOptions
    RedisExt -->|registers| RedisRetriever

    subgraph "Sample Application"
        direction TB
        SampleProgram["Program.cs"]:::app
        ValuesCtrl["ValuesController.cs"]:::app
        MoreValuesCtrl["MoreValuesController.cs"]:::app
        AppSettings["appsettings.json"]:::app
    end
    UseEndpoints --> SampleProgram
    SampleProgram --> ValuesCtrl
    SampleProgram --> MoreValuesCtrl
    SampleProgram --> AppSettings

    click HttpCacheHeadersMiddleware "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers/HttpCacheHeadersMiddleware.cs"
    click StoreKeyGen "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers/DefaultStoreKeyGenerator.cs"
    click Interfaces "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers/Interfaces/IValidatorValueStore.cs"
    click InMemoryStore "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers/Stores/InMemoryValidatorValueStore.cs"
    click Serializer "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers/Serialization/DefaultStoreKeySerializer.cs"
    click ETagGen "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers/DefaultStrongETagGenerator.cs"
    click ETagInj "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers/DefaultETagInjector.cs"
    click LastModInj "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers/DefaultLastModifiedInjector.cs"
    click DateParser "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers/DefaultDateParser.cs"
    click StoreKeyAcc "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers/StoreKeyAccessor.cs"
    click ValidatorInv "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers/ValidatorValueInvalidator.cs"
    click DistInterfaces "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers.DistributedStore/Interfaces/IRetrieveDistributedCacheKeys.cs"
    click DistributedStore "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers.DistributedStore/Stores/DistributedCacheValidatorValueStore.cs"
    click RedisExt "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers.DistributedStore.Redis/Extensions/ServicesExtensions.cs"
    click RedisOptions "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers.DistributedStore.Redis/Options/RedisDistributedCacheKeyRetrieverOptions.cs"
    click RedisRetriever "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers.DistributedStore.Redis/Stores/RedisDistributedCacheKeyRetriever.cs"
    click SampleProgram "https://github.com/kevindockx/httpcacheheaders/blob/master/sample/Marvin.Cache.Headers.Sample/Program.cs"
    click ValuesCtrl "https://github.com/kevindockx/httpcacheheaders/blob/master/sample/Marvin.Cache.Headers.Sample/Controllers/ValuesController.cs"
    click MoreValuesCtrl "https://github.com/kevindockx/httpcacheheaders/blob/master/sample/Marvin.Cache.Headers.Sample/Controllers/MoreValuesController.cs"
    click AppSettings "https://github.com/kevindockx/httpcacheheaders/blob/master/sample/Marvin.Cache.Headers.Sample/appsettings.json"

    class AppBuilderExt,ServicesExt ext
    click AppBuilderExt "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers/Extensions/AppBuilderExtensions.cs"
    click ServicesExt "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers/Extensions/ServicesExtensions.cs"
    Attributes["Attributes (HttpCacheExpirationAttribute, HttpCacheValidationAttribute, HttpCacheIgnoreAttribute)"]:::ext
    click Attributes "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers/Attributes/HttpCacheExpirationAttribute.cs"
    click Attributes "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers/Attributes/HttpCacheValidationAttribute.cs"
    click Attributes "https://github.com/kevindockx/httpcacheheaders/blob/master/src/Marvin.Cache.Headers/Attributes/HttpCacheIgnoreAttribute.cs"
```
