Implementation:LMCache LMCache LMCBlenderBuilder Get Or Create
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Inference_Optimization |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
Concrete tool for creating or retrieving the CacheBlend blender singleton, provided by the LMCBlenderBuilder class.
Description
The LMCBlenderBuilder.get_or_create class method implements a singleton-per-instance_id pattern for LMCBlender instances. It creates the blender with references to the cache engine, GPU connector, and blend config. The blender internally initializes a FusedRope encoder for RoPE position recovery.
Usage
Called by the connector's _init_connector_state when enable_blending=True. Returns the existing blender if already created for this instance_id.
Code Reference
Source Location
- Repository: LMCache
- File: lmcache/v1/compute/blend/utils.py
- Lines: L25-L51
Signature
class LMCBlenderBuilder:
@classmethod
def get_or_create(
cls,
instance_id: str,
cache_engine: LMCacheEngine,
gpu_connector: GPUConnectorInterface,
config: LMCacheEngineConfig,
) -> LMCBlender:
"""Get or create a blender instance.
Args:
instance_id: Engine instance ID
cache_engine: Cache engine reference
gpu_connector: GPU connector for KV buffer access
config: Blend-enabled config
Returns:
LMCBlender instance
"""
Import
from lmcache.v1.compute.blend.utils import LMCBlenderBuilder
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| instance_id | str | Yes | Engine instance identifier |
| cache_engine | LMCacheEngine | Yes | Cache engine reference |
| gpu_connector | GPUConnectorInterface | Yes | GPU memory connector |
| config | LMCacheEngineConfig | Yes | Blend-enabled config |
Outputs
| Name | Type | Description |
|---|---|---|
| return | LMCBlender | Blender instance with FusedRope for position recovery |