Implementation:LMCache LMCache Audit Connector
| Knowledge Sources | |
|---|---|
| Domains | Caching, Observability, Storage Connectors |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
AuditConnector is a transparent auditing wrapper for RemoteConnector that dynamically intercepts and logs all connector method calls with timing, checksums, and error tracking.
Description
The AuditConnector uses a custom metaclass (AuditConnectorMeta) to automatically generate wrapper methods for every method defined on the RemoteConnector interface. Each wrapped method logs the start, success (with elapsed time in milliseconds), or failure of the operation. Methods decorated with @NotAudit are forwarded to the underlying connector without any logging overhead. The connector also supports optional SHA-256 checksum calculation and verification for put and get operations, controlled via the audit_calc_checksum and audit_verify_checksum configuration flags. A configurable set of excluded commands can bypass auditing as well.
Usage
Use AuditConnector when you need to diagnose remote storage performance issues, verify data integrity between put and get operations, or gather detailed operational logs for remote connector interactions. It is typically instantiated by wrapping an existing RemoteConnector instance and is configured through the LMCacheEngineConfig.extra_config dictionary.
Code Reference
Source Location
- Repository: LMCache
- File: lmcache/v1/storage_backend/connector/audit_connector.py
- Lines: 1-320
Signature
class AuditConnectorMeta(abc.ABCMeta):
def __new__(mcs, name, bases, namespace): ...
class AuditConnector(RemoteConnector, metaclass=AuditConnectorMeta):
def __init__(
self, real_connector: RemoteConnector, lmcache_config: LMCacheEngineConfig
): ...
def _calculate_checksum(self, data: bytes) -> str: ...
async def _audit_put(self, key: CacheEngineKey, memory_obj: MemoryObj): ...
async def _audit_get(self, key: CacheEngineKey) -> Optional[MemoryObj]: ...
Import
from lmcache.v1.storage_backend.connector.audit_connector import AuditConnector
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| real_connector | RemoteConnector | Yes | The underlying remote connector whose methods will be audited |
| lmcache_config | LMCacheEngineConfig | Yes | Engine configuration containing extra_config for audit settings (audit_verify_checksum, audit_calc_checksum, audit_exclude_cmds) |
Outputs
| Name | Type | Description |
|---|---|---|
| AuditConnector | RemoteConnector | A wrapper that transparently delegates all RemoteConnector methods while logging performance and optionally verifying checksums |
Usage Examples
from lmcache.v1.storage_backend.connector.audit_connector import AuditConnector
from lmcache.v1.storage_backend.connector.redis_connector import RedisConnector
# Wrap an existing connector with auditing
redis_connector = RedisConnector(url, loop, local_cpu_backend)
audit_connector = AuditConnector(redis_connector, lmcache_config)
# All operations are now audited with timing and optional checksums
await audit_connector.put(key, memory_obj) # Logs PUT|START, PUT|SUCCESS|Cost:X.XXms
result = await audit_connector.get(key) # Logs GET|START, GET|SUCCESS or GET|MISMATCH