Implementation:LMCache LMCache External Connector Adapter
| Knowledge Sources | |
|---|---|
| Domains | Storage Backend, Plugin System |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
ExternalConnectorAdapter dynamically loads user-defined remote connector implementations via URL-based module discovery.
Description
The ExternalConnectorAdapter class extends ConnectorAdapter to support pluggable external connectors. It parses a URL of the form external://host:port/module_path/?connector_name=ConnectorName, dynamically imports the specified Python module using importlib, and instantiates the named connector class. The loaded class must be a subclass of RemoteConnector. Only single-host configurations are supported; comma-separated multi-host URLs raise a ValueError.
Usage
Use this adapter when integrating a custom or third-party key-value store connector that is not natively supported by LMCache. The external connector module must be importable from the Python path and must define a class that inherits from RemoteConnector.
Code Reference
Source Location
- Repository: LMCache
- File: lmcache/v1/storage_backend/connector/external_adapter.py
- Lines: 1-75
Signature
class ExternalConnectorAdapter(ConnectorAdapter):
def __init__(self) -> None: ...
def create_connector(self, context: ConnectorContext) -> RemoteConnector: ...
Import
from lmcache.v1.storage_backend.connector.external_adapter import ExternalConnectorAdapter
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| context | ConnectorContext | Yes | Contains the URL (format: external://host:port/module_path/?connector_name=ClassName), event loop, local CPU backend, and config
|
Outputs
| Name | Type | Description |
|---|---|---|
| return | RemoteConnector | An instance of the dynamically loaded external connector class |
Usage Examples
# URL format for external connectors:
# external://host:0/my_module.my_submodule/?connector_name=MyCustomConnector
# The adapter is typically created via the ConnectorManager auto-discovery:
from lmcache.v1.storage_backend.connector import CreateConnector
connector = CreateConnector(
url="external://host:0/my_custom_connector.module/?connector_name=MyConnector",
loop=event_loop,
local_cpu_backend=cpu_backend,
config=config,
metadata=metadata,
)