Implementation:LMCache LMCache Load Engine Config With Overrides
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Configuration |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
Concrete tool for loading and validating LMCache engine configuration provided by the lmcache library.
Description
The load_engine_config_with_overrides function is the primary entry point for creating an LMCacheEngineConfig instance. It delegates to a generic config loading utility that reads YAML files, applies environment variable overrides (all prefixed with LMCACHE_), and merges programmatic overrides. The resulting config object is validated to ensure consistency across all enabled features.
The LMCacheEngineConfig class is dynamically generated via create_config_class using a central _CONFIG_DEFINITIONS dictionary that defines all fields with types, defaults, and environment variable converters.
Usage
Import this function when initializing any LMCache deployment. It is always the first API call in any workflow. Set configuration via YAML file (pointed to by LMCACHE_CONFIG_FILE environment variable), individual LMCACHE_* environment variables, or pass a dictionary of overrides.
Code Reference
Source Location
- Repository: LMCache
- File: lmcache/v1/config.py
- Lines: L715-L754 (LMCacheEngineConfig creation and load function)
Signature
def load_engine_config_with_overrides(
config_file_path: Optional[str] = None,
overrides: Optional[Dict[str, Any]] = None,
) -> LMCacheEngineConfig:
"""
Load engine configuration with support for file, env vars, and overrides.
Args:
config_file_path: Optional direct path to config file
overrides: Optional dictionary of configuration overrides
Returns:
Loaded and validated LMCacheEngineConfig instance
"""
Import
from lmcache.v1.config import load_engine_config_with_overrides, LMCacheEngineConfig
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config_file_path | Optional[str] | No | Direct path to YAML config file. If None, reads LMCACHE_CONFIG_FILE env var |
| overrides | Optional[Dict[str, Any]] | No | Dictionary of configuration overrides applied last |
Outputs
| Name | Type | Description |
|---|---|---|
| return | LMCacheEngineConfig | Validated configuration instance with all fields set |
Usage Examples
Via Environment Variables
import os
os.environ["LMCACHE_CHUNK_SIZE"] = "256"
os.environ["LMCACHE_LOCAL_CPU"] = "True"
os.environ["LMCACHE_MAX_LOCAL_CPU_SIZE"] = "5"
from lmcache.v1.config import load_engine_config_with_overrides
config = load_engine_config_with_overrides()
Via YAML File
import os
os.environ["LMCACHE_CONFIG_FILE"] = "/path/to/config.yaml"
from lmcache.v1.config import load_engine_config_with_overrides
config = load_engine_config_with_overrides()
Via Explicit Path and Overrides
from lmcache.v1.config import load_engine_config_with_overrides
config = load_engine_config_with_overrides(
config_file_path="/path/to/config.yaml",
overrides={"chunk_size": 512, "local_cpu": True}
)