# lmcache/lmcache architecture

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

- Interactive diagram: https://gitdiagram.com/lmcache/lmcache
- Repository: https://github.com/lmcache/lmcache
- Video tour (about a minute): https://gitdiagram.com/lmcache/lmcache/video

## Overview

LMCache is a KV-cache management layer for LLM inference: serving engines hand cache data to LMCache, which can look up, reuse, and offload it across memory tiers and remote stores. Engine integrations and GPU/layout handling connect serving-engine cache formats to the cache runtime; distributed storage adds L1/L2 management, transfer, and coordination. Other major capabilities include non-prefix CacheBlend reuse, pluggable serialization, and observability. The README documents these product branches; sampled source is partial, so links between unsampled subsystems are shown only where supported.

Main entry points: [`lmcache/v1/cache_engine.py`](https://github.com/lmcache/lmcache/blob/dev/lmcache/v1/cache_engine.py) (Cache engine), [`lmcache/v1/distributed/storage_manager.py`](https://github.com/lmcache/lmcache/blob/dev/lmcache/v1/distributed/storage_manager.py) (Tier manager), [`lmcache/integration`](https://github.com/lmcache/lmcache/tree/dev/lmcache/integration) (Engine adapters), [`lmcache/v1/storage_backend/storage_manager.py`](https://github.com/lmcache/lmcache/blob/dev/lmcache/v1/storage_backend/storage_manager.py) (Storage manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_engine["Engine integration"]
  node_integration["Engine adapters"]
  node_factory["vLLM factory"]
  node_gpu["GPU connectors"]
  node_formats["KV layouts"]
end

subgraph group_cache["Cache runtime"]
  node_enginecore["Cache engine<br/>[cache_engine.py]"]
  node_storage["Storage manager<br/>[storage_manager.py]"]
  node_serde["Serialization"]
end

subgraph group_distributed["Distributed storage"]
  node_l1["L1 memory<br/>[l1_manager.py]"]
  node_l2["L2 adapters"]
  node_tiermanager["Tier manager<br/>[storage_manager.py]"]
  node_controllers["Storage controllers"]
  node_transfer["Transfer channels"]
  node_coordinator["MP coordinator"]
end

subgraph group_reuse["Reuse and transform"]
  node_lookup["Lookup clients"]
  node_blend["CacheBlend"]
  node_attention["Attention reuse"]
end

subgraph group_operations["Operations"]
  node_api["Management APIs"]
  node_observability["Observability"]
  node_cli["CLI"]
end

node_serving(("Serving engine"))
node_remote[("Remote stores")]

node_serving -->|"integrates"| node_integration
node_factory -->|"creates"| node_enginecore
node_integration -->|"detects layouts"| node_formats
node_integration -->|"connects tensors"| node_gpu
node_enginecore -->|"stores and loads"| node_storage
node_storage -->|"uses tiers"| node_tiermanager
node_tiermanager -->|"manages memory"| node_l1
node_tiermanager -->|"manages adapters"| node_l2
node_tiermanager -->|"starts controllers"| node_controllers
node_l2 -->|"offloads cache"| node_remote
node_tiermanager -->|"transfers cache"| node_transfer
node_serde -->|"transforms data"| node_l2
node_coordinator -.->|"coordinates lookup"| node_lookup
node_lookup -->|"checks cache"| node_storage
node_blend -->|"enables non-prefix reuse"| node_enginecore
node_attention -->|"reuses cached KV"| node_enginecore
node_api -->|"manages runtime"| node_enginecore
node_observability -->|"monitors cache"| node_enginecore
node_cli -.->|"queries service"| node_coordinator

click node_integration "https://github.com/lmcache/lmcache/tree/dev/lmcache/integration"
click node_factory "https://github.com/lmcache/lmcache/blob/dev/lmcache/integration/vllm/vllm_service_factory.py"
click node_gpu "https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/gpu_connector"
click node_formats "https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/gpu_connector/kv_format"
click node_enginecore "https://github.com/lmcache/lmcache/blob/dev/lmcache/v1/cache_engine.py"
click node_storage "https://github.com/lmcache/lmcache/blob/dev/lmcache/v1/storage_backend/storage_manager.py"
click node_serde "https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/distributed/serde"
click node_l1 "https://github.com/lmcache/lmcache/blob/dev/lmcache/v1/distributed/l1_manager.py"
click node_l2 "https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/distributed/l2_adapters"
click node_tiermanager "https://github.com/lmcache/lmcache/blob/dev/lmcache/v1/distributed/storage_manager.py"
click node_controllers "https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/distributed/storage_controllers"
click node_transfer "https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/distributed/transfer_channel"
click node_coordinator "https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/mp_coordinator"
click node_lookup "https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/lookup_client"
click node_blend "https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/compute/blend"
click node_attention "https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/compute/attention"
click node_api "https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/internal_api_server"
click node_observability "https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/mp_observability"
click node_cli "https://github.com/lmcache/lmcache/tree/dev/lmcache/cli"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_integration,node_factory,node_gpu,node_formats toneBlue
class node_enginecore,node_storage,node_serde,node_remote toneAmber
class node_l1,node_l2,node_tiermanager,node_controllers,node_transfer,node_coordinator toneMint
class node_lookup,node_blend,node_attention toneRose
class node_api,node_observability,node_cli,node_serving toneIndigo
```

## Components

### Engine integration

- [Engine adapters](https://github.com/lmcache/lmcache/tree/dev/lmcache/integration): `lmcache/integration`
- [vLLM factory](https://github.com/lmcache/lmcache/blob/dev/lmcache/integration/vllm/vllm_service_factory.py): `lmcache/integration/vllm/vllm_service_factory.py`
- [GPU connectors](https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/gpu_connector): `lmcache/v1/gpu_connector`
- [KV layouts](https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/gpu_connector/kv_format): `lmcache/v1/gpu_connector/kv_format`

### Cache runtime

- [Cache engine](https://github.com/lmcache/lmcache/blob/dev/lmcache/v1/cache_engine.py): `lmcache/v1/cache_engine.py`
- [Storage manager](https://github.com/lmcache/lmcache/blob/dev/lmcache/v1/storage_backend/storage_manager.py): `lmcache/v1/storage_backend/storage_manager.py`
- [Serialization](https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/distributed/serde): `lmcache/v1/distributed/serde`

### Distributed storage

- [L1 memory](https://github.com/lmcache/lmcache/blob/dev/lmcache/v1/distributed/l1_manager.py): `lmcache/v1/distributed/l1_manager.py`
- [L2 adapters](https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/distributed/l2_adapters): `lmcache/v1/distributed/l2_adapters`
- [Tier manager](https://github.com/lmcache/lmcache/blob/dev/lmcache/v1/distributed/storage_manager.py): `lmcache/v1/distributed/storage_manager.py`
- [Storage controllers](https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/distributed/storage_controllers): `lmcache/v1/distributed/storage_controllers`
- [Transfer channels](https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/distributed/transfer_channel): `lmcache/v1/distributed/transfer_channel`
- [MP coordinator](https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/mp_coordinator): `lmcache/v1/mp_coordinator`

### Reuse and transform

- [Lookup clients](https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/lookup_client): `lmcache/v1/lookup_client`
- [CacheBlend](https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/compute/blend): `lmcache/v1/compute/blend`
- [Attention reuse](https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/compute/attention): `lmcache/v1/compute/attention`

### Operations

- [Management APIs](https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/internal_api_server): `lmcache/v1/internal_api_server`
- [Observability](https://github.com/lmcache/lmcache/tree/dev/lmcache/v1/mp_observability): `lmcache/v1/mp_observability`
- [CLI](https://github.com/lmcache/lmcache/tree/dev/lmcache/cli): `lmcache/cli`

### Other components

- **Serving engine**
- **Remote stores**

## Connections

- Serving engine → Engine adapters: integrates
- vLLM factory → Cache engine: creates
- Engine adapters → KV layouts: detects layouts
- Engine adapters → GPU connectors: connects tensors
- Cache engine → Storage manager: stores and loads
- Storage manager → Tier manager: uses tiers
- Tier manager → L1 memory: manages memory
- Tier manager → L2 adapters: manages adapters
- Tier manager → Storage controllers: starts controllers
- L2 adapters → Remote stores: offloads cache
- Tier manager → Transfer channels: transfers cache
- Serialization → L2 adapters: transforms data
- MP coordinator → Lookup clients: coordinates lookup
- Lookup clients → Storage manager: checks cache
- CacheBlend → Cache engine: enables non-prefix reuse
- Attention reuse → Cache engine: reuses cached KV
- Management APIs → Cache engine: manages runtime
- Observability → Cache engine: monitors cache
- CLI → MP coordinator: queries service
