Skip to content

API Reference

BaseTTLCache

Bases: ABC

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

clear_expired() abstractmethod async

Clear expired values from the cache.

close() abstractmethod async

Close the cache, called when BaseClient is closed.

delete(key) abstractmethod async

Delete the value from the cache.

Parameters:

Name Type Description Default
key str

The key to delete.

required

get(key) abstractmethod async

Get a value from the cache.

Returns:

Type Description
str | None

The value if it exists, otherwise None.

set(key, value, ttl) abstractmethod async

Set the value in the cache.

Parameters:

Name Type Description Default
key str

The key to set.

required
value str

The value to set.

required
ttl int

The time to live in seconds.

required

start() abstractmethod async

Start the cache, called when BaseClient is started.

MemoryCache

Bases: BaseTTLCache

In-memory cache implementation.

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

RedisCache

Bases: BaseTTLCache

Redis cache implementation.

This cache uses Redis for distributed and persistent caching.

SQLiteCache

Bases: BaseTTLCache

SQLite cache implementation.

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