DbUnify.SQLite3 package

Subpackages

Submodules

DbUnify.SQLite3.Cache module

class DbUnify.SQLite3.Cache.Cache(ttl: int = 60)[source]

Bases: object

Cache Class

The Cache class provides methods for storing and retrieving query results in a cache to improve performance. It supports automatic cache expiration based on a time-to-live (TTL) value.

cache

A dictionary to store cached query results and their expiration times.

Type:

Dict[str, Tuple[Any, float]]

ttl

Time-to-live for cache entries in seconds.

Type:

int

__init__(self, ttl)[source]

Initializes the Cache instance with a TTL value.

set(self, key, value)[source]

Stores a query result in the cache with an expiration time.

get(self, key)[source]

Retrieves a query result from the cache if it exists and is not expired.

is_expired(self, expiration)[source]

Checks if a cache entry is expired.

_clean_expired(self)[source]

Removes expired cache entries.

get(key: str) Any[source]

Retrieve a query result from the cache if it exists and is not expired.

Parameters:

key (str) – The cache key, usually the query string.

Returns:

The cached query result, or None if the cache entry does not exist or is expired.

Return type:

Any

is_expired(expiration: float) bool[source]

Check if a cache entry is expired.

Parameters:

expiration (float) – The expiration time of the cache entry.

Returns:

True if the cache entry is expired, False otherwise.

Return type:

bool

set(key: str, value: Any) None[source]

Store a query result in the cache with an expiration time.

Parameters:
  • key (str) – The cache key, usually the query string.

  • value (Any) – The query result to be cached.

DbUnify.SQLite3.QueryBuilder module

Module contents