Skip to content

Types & Protocols

Most parts of psycache can be replaced by implementing the appropriate protocols.

psycache.typing.AsyncCachePool

Bases: Protocol

Protocol for a class that provides a way to connect to a psycopg.AsyncConnection.

Implemented by adapters that wrap a higher-level connection source (for example, a psycopg pool or a SQLAlchemy engine) and hand out an auto-commit psycopg.AsyncConnection.

connect()

Connect to the database and return a context manager for an auto-commit connection.

psycache.typing.CacheCleanupSpan

Bases: Protocol

Span interface for cache cleanup operations.

record_cleanup(num_deleted)

Record a successful cleanup with the number of deleted entries.

psycache.typing.CacheFlushSpan

Bases: Protocol

Span interface for cache flush operations.

record_flush(num_flushed)

Record a successful cache flush with the number of flushed entries.

psycache.typing.CacheGetSpan

Bases: Protocol

Span interface for cache get operations.

record_cache_hit(item_size)

Record a successful cache hit with the item size in bytes.

record_cache_miss()

Record a cache miss (key not found or expired).

psycache.typing.CacheInstrumentation

Bases: Protocol

Cache instrumentation provider.

start_cache_cleanup_span()

Start a span for a cache cleanup operation.

start_cache_flush_span()

Start a span for a cache flush operation.

start_cache_get_span(key, name)

Start a span for a cache get operation.

start_cache_put_span(key, name)

Start a span for a cache put operation.

start_cache_remove_span(key)

Start a span for a cache removal operation.

psycache.typing.CachePool

Bases: Protocol

Protocol for a class that provides a way to connect to a psycopg.Connection.

Implemented by adapters that wrap a higher-level connection source (for example, a psycopg pool or a SQLAlchemy engine) and hand out an auto-commit psycopg.Connection.

connect()

Connect to the database and return a context manager for an auto-commit connection.

psycache.typing.CachePutSpan

Bases: Protocol

Span interface for cache write (put) operations.

record_put(item_size)

Record a successful cache write with the item size in bytes.

psycache.typing.CacheRemoveSpan

Bases: Protocol

Span interface for cache remove operations.

record_removed()

Record a successful cache removal.