Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:LMCache LMCache LMCacheEngineBuilder Destroy

From Leeroopedia


Knowledge Sources
Domains Infrastructure, Resource_Management
Last Updated 2026-02-09 00:00 GMT

Overview

Concrete tool for destroying LMCache engine instances and releasing all associated resources, provided by the LMCacheEngineBuilder class.

Description

The LMCacheEngineBuilder.destroy class method performs orderly shutdown of a cache engine instance. It stops the statistics logger, closes the engine (releasing storage backends, GPU connectors, transfer channels, ZMQ sockets), removes the instance from tracking dictionaries, and destroys the statistics monitor singleton.

Usage

Call this method when shutting down the serving engine or cleaning up between runs. It is typically called in a finally block or context manager exit.

Code Reference

Source Location

  • Repository: LMCache
  • File: lmcache/v1/cache_engine.py
  • Lines: L1909-L1951

Signature

class LMCacheEngineBuilder:
    @classmethod
    def destroy(cls, instance_id: str) -> None:
        """Close and delete the LMCacheEngine instance by the instance ID.

        Args:
            instance_id: Engine instance identifier (typically "lmcache")
        """

Import

from lmcache.v1.cache_engine import LMCacheEngineBuilder

I/O Contract

Inputs

Name Type Required Description
instance_id str Yes Engine instance identifier (typically ENGINE_NAME = "lmcache")

Outputs

Name Type Description
(none) None All resources released: stats logger stopped, engine closed, dictionaries cleaned

Usage Examples

Cleanup After Inference

from lmcache.v1.cache_engine import LMCacheEngineBuilder
from lmcache.integration.vllm.utils import ENGINE_NAME

# After inference is complete
LMCacheEngineBuilder.destroy(ENGINE_NAME)  # ENGINE_NAME = "lmcache"

Context Manager Pattern

import contextlib
from lmcache.v1.cache_engine import LMCacheEngineBuilder
from lmcache.integration.vllm.utils import ENGINE_NAME

@contextlib.contextmanager
def build_llm_with_lmcache(model):
    llm = create_llm(model)
    try:
        yield llm
    finally:
        LMCacheEngineBuilder.destroy(ENGINE_NAME)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment