Implementation:LMCache LMCache Multiprocess Protocol
| Knowledge Sources | |
|---|---|
| Domains | Inter-Process Communication, RPC Protocol |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
This module defines the RPC protocol for communication between LMCache core server and worker clients, specifying request types, payload structures, and handler types.
Description
The protocol is organized around a RequestType enum that enumerates all supported operations: REGISTER_KV_CACHE, UNREGISTER_KV_CACHE, STORE, RETRIEVE, LOOKUP, CLEAR, GET_CHUNK_SIZE, and NOOP. Each request type maps to a ProtocolDefinition that declares the expected payload classes, response class, and handler type. Handler types include SYNC (runs directly in the main loop), BLOCKING (runs in a thread pool), and NON_BLOCKING (reserved for future use). Helper functions get_payload_classes, get_response_class, and get_handler_type provide lookup access to the protocol definitions. The key type used throughout the protocol is IPCCacheEngineKey.
Usage
Use this module when implementing or extending the multiprocess RPC layer between LMCache workers and the core cache server. The protocol definitions drive message encoding/decoding and handler dispatch.
Code Reference
Source Location
- Repository: LMCache
- File: lmcache/v1/multiprocess/protocol.py
- Lines: 1-172
Signature
class RequestType(enum.Enum):
REGISTER_KV_CACHE = ...
UNREGISTER_KV_CACHE = ...
STORE = ...
RETRIEVE = ...
LOOKUP = ...
CLEAR = ...
GET_CHUNK_SIZE = ...
NOOP = ...
class HandlerType(enum.Enum):
SYNC = ...
BLOCKING = ...
NON_BLOCKING = ...
@dataclass
class ProtocolDefinition:
payload_classes: list[Any]
response_class: Optional[Any]
handler_type: HandlerType
def get_payload_classes(req_type: RequestType) -> list[Any]: ...
def get_response_class(req_type: RequestType) -> Optional[Any]: ...
def get_handler_type(req_type: RequestType) -> HandlerType: ...
Import
from lmcache.v1.multiprocess.protocol import (
RequestType,
HandlerType,
ProtocolDefinition,
get_payload_classes,
get_response_class,
get_handler_type,
KeyType,
InstanceID,
)
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| req_type | RequestType | Yes | The request type to look up in the protocol definitions |
Outputs
| Name | Type | Description |
|---|---|---|
| get_payload_classes | list[Any] | List of expected payload types for the given request |
| get_response_class | Optional[Any] | Expected response type, or None if the request has no response |
| get_handler_type | HandlerType | Whether the handler is SYNC, BLOCKING, or NON_BLOCKING |
The protocol defines the following operations:
| Request Type | Payload | Response | Handler |
|---|---|---|---|
| REGISTER_KV_CACHE | [int, KVCache] | None | SYNC |
| UNREGISTER_KV_CACHE | [int] | None | SYNC |
| STORE | [list[KeyType], int, list[int], bytes] | tuple[bytes, bool] | BLOCKING |
| RETRIEVE | [list[KeyType], int, list[int], bytes] | tuple[bytes, list[bool]] | BLOCKING |
| LOOKUP | [list[KeyType], Optional[bool]] | list[bool] | BLOCKING |
| CLEAR | [] | None | BLOCKING |
| GET_CHUNK_SIZE | [] | int | SYNC |
| NOOP | [] | str | SYNC |
Usage Examples
from lmcache.v1.multiprocess.protocol import RequestType, get_payload_classes, get_handler_type
# Look up protocol definition for STORE
payload_types = get_payload_classes(RequestType.STORE)
handler = get_handler_type(RequestType.STORE)
print(f"STORE payload: {payload_types}, handler: {handler}")