lmcache.storage_backend.connector package#

Submodules#

lmcache.storage_backend.connector.base_connector module#

class lmcache.storage_backend.connector.base_connector.ConnectorType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

BYTES = 1#
TENSOR = 2#
class lmcache.storage_backend.connector.base_connector.RemoteBytesConnector[source]#

Bases: RemoteConnector

class lmcache.storage_backend.connector.base_connector.RemoteConnector[source]#

Interface for remote connector

abstract close() None[source]#

Close remote server

abstract exists(key: str) bool[source]#

Check if the remote server contains the key

Input:

key: a string

Returns:

True if the cache engine contains the key, False otherwise

abstract get(key: str) bytes | Tensor | None[source]#

Get the objects (bytes or Tensor) of the corresponding key

Input:

key: the key of the corresponding object

Returns:

The objects (bytes or Tensor) of the corresponding key Return None if the key does not exist

abstract list() List[str][source]#

List all keys in the remote server

Returns:

A list of keys in the remote server

abstract set(key: str, obj: bytes | Tensor) None[source]#

Send the objects (bytes or Tensor) with the corresponding key directly to the remote server

Input:

key: the key of the corresponding object obj: the object (bytes or Tensor) of the corresponding key

class lmcache.storage_backend.connector.base_connector.RemoteConnectorDebugWrapper(connector: RemoteConnector)[source]#

Bases: RemoteConnector

close() None[source]#

Close remote server

exists(key: str) bool[source]#

Check if the remote server contains the key

Input:

key: a string

Returns:

True if the cache engine contains the key, False otherwise

get(key: str) bytes | Tensor | None[source]#

Get the objects (bytes or Tensor) of the corresponding key

Input:

key: the key of the corresponding object

Returns:

The objects (bytes or Tensor) of the corresponding key Return None if the key does not exist

list() List[str][source]#

List all keys in the remote server

Returns:

A list of keys in the remote server

set(key: str, obj: bytes | Tensor) None[source]#

Send the objects (bytes or Tensor) with the corresponding key directly to the remote server

Input:

key: the key of the corresponding object obj: the object (bytes or Tensor) of the corresponding key

class lmcache.storage_backend.connector.base_connector.RemoteTensorConnector[source]#

Bases: RemoteConnector

lmcache.storage_backend.connector.base_connector.check_connector_type(connector: RemoteConnector) ConnectorType[source]#

lmcache.storage_backend.connector.lm_connector module#

class lmcache.storage_backend.connector.lm_connector.LMCServerConnector(host, port)[source]#

Bases: RemoteBytesConnector

close()[source]#

Close remote server

exists(key: str) bool[source]#

Check if the remote server contains the key

Input:

key: a string

Returns:

True if the cache engine contains the key, False otherwise

get(key: str) bytes | None[source]#

Get the objects (bytes or Tensor) of the corresponding key

Input:

key: the key of the corresponding object

Returns:

The objects (bytes or Tensor) of the corresponding key Return None if the key does not exist

list() List[str][source]#

List all keys in the remote server

Returns:

A list of keys in the remote server

receive_all(n)[source]#
send_all(data)[source]#

Thread-safe function to send the data

set(key: str, obj: bytes)[source]#

Send the objects (bytes or Tensor) with the corresponding key directly to the remote server

Input:

key: the key of the corresponding object obj: the object (bytes or Tensor) of the corresponding key

lmcache.storage_backend.connector.redis_connector module#

class lmcache.storage_backend.connector.redis_connector.RedisConnector(host: str, port: int)[source]#

Bases: RemoteBytesConnector

The remote url should start with “redis://” and only have one host-port pair

close()[source]#

Close remote server

exists(key: str) bool[source]#

Check if the remote server contains the key

Input:

key: a string

Returns:

True if the cache engine contains the key, False otherwise

get(key: str) bytes | None[source]#

Get the objects (bytes or Tensor) of the corresponding key

Input:

key: the key of the corresponding object

Returns:

The objects (bytes or Tensor) of the corresponding key Return None if the key does not exist

list()[source]#

List all keys in the remote server

Returns:

A list of keys in the remote server

set(key: str, obj: bytes) None[source]#

Send the objects (bytes or Tensor) with the corresponding key directly to the remote server

Input:

key: the key of the corresponding object obj: the object (bytes or Tensor) of the corresponding key

class lmcache.storage_backend.connector.redis_connector.RedisSentinelConnector(hosts_and_ports: List[Tuple[str, str | int]])[source]#

Bases: RemoteBytesConnector

Uses redis.Sentinel to connect to a Redis cluster. The hosts are specified in the config file, started with “redis-sentinel://” and separated by commas.

Example

remote_url: “redis-sentinel://localhost:26379,localhost:26380,localhost:26381”

Extra environment variables: - REDIS_SERVICE_NAME (required) – service name for redis. - REDIS_TIMEOUT (optional) – Timeout in seconds, default is 1 if not set

ENV_REDIS_SERVICE_NAME = 'REDIS_SERVICE_NAME'#
ENV_REDIS_TIMEOUT = 'REDIS_TIMEOUT'#
close()[source]#

Close remote server

exists(key: str) bool[source]#

Check if the remote server contains the key

Input:

key: a string

Returns:

True if the cache engine contains the key, False otherwise

get(key: str) bytes | None[source]#

Get the objects (bytes or Tensor) of the corresponding key

Input:

key: the key of the corresponding object

Returns:

The objects (bytes or Tensor) of the corresponding key Return None if the key does not exist

list()[source]#

List all keys in the remote server

Returns:

A list of keys in the remote server

set(key: str, obj: bytes) None[source]#

Send the objects (bytes or Tensor) with the corresponding key directly to the remote server

Input:

key: the key of the corresponding object obj: the object (bytes or Tensor) of the corresponding key