Skip to content

API Reference

cache

Classes:

  • BaseTTLCache

    Base class for TTL cache, inherit from this class to implement your own cache.

  • MemoryCache

    In-memory cache implementation.

  • RedisCache

    Redis cache implementation.

  • SQLiteCache

    SQLite cache implementation.

BaseTTLCache

Base class for TTL cache, inherit from this class to implement your own cache.

Methods:

  • clear_expired

    Clear expired values from the cache.

  • close

    Close the cache, called when BaseClient is closed.

  • delete

    Delete the value from the cache.

  • get

    Get a value from the cache.

  • set

    Set the value in the cache.

  • start

    Start the cache, called when BaseClient is started.

clear_expired abstractmethod async

clear_expired() -> None

Clear expired values from the cache.

close abstractmethod async

close() -> None

Close the cache, called when BaseClient is closed.

delete abstractmethod async

delete(key: str) -> None

Delete the value from the cache.

Parameters:

  • key
    (str) –

    The key to delete.

get abstractmethod async

get(key: str) -> str | None

Get a value from the cache.

Returns:

  • str | None

    The value if it exists, otherwise None.

set abstractmethod async

set(key: str, value: str, ttl: int) -> None

Set the value in the cache.

Parameters:

  • key
    (str) –

    The key to set.

  • value
    (str) –

    The value to set.

  • ttl
    (int) –

    The time to live in seconds.

start abstractmethod async

start() -> None

Start the cache, called when BaseClient is started.

MemoryCache

In-memory cache implementation.

This cache is not persistent and will be cleared when the program exits.

Methods:

clear_expired async

clear_expired() -> None

close async

close() -> None

delete async

delete(key: str) -> None

get async

get(key: str) -> str | None

set async

set(key: str, value: str, ttl: int) -> None

start async

start() -> None

RedisCache

Redis cache implementation.

This cache uses Redis for distributed and persistent caching.

Methods:

clear_expired async

clear_expired() -> None

close async

close() -> None

delete async

delete(key: str) -> None

get async

get(key: str) -> str | None

set async

set(key: str, value: str, ttl: int) -> None

start async

start() -> None

SQLiteCache

SQLite cache implementation.

This cache is persistent and will be saved to the specified file.

Methods:

Attributes:

  • conn (Connection) –

conn property

conn: Connection

clear_expired async

clear_expired() -> None

close async

close() -> None

delete async

delete(key: str) -> None

get async

get(key: str) -> str | None

set async

set(key: str, value: str, ttl: int) -> None

start async

start() -> None