domain.protocols.provider_connection_cache_protocol¶
src.domain.protocols.provider_connection_cache_protocol
¶
Provider connection cache protocol for fast lookups.
This module defines the port (interface) for provider connection caching. Infrastructure layer implements with Redis for <5ms lookups.
Reference
- docs/architecture/cache-key-patterns.md
Classes¶
ProviderConnectionCache
¶
Bases: Protocol
Provider connection cache protocol (port) for fast lookups.
Provides <5ms provider connection lookups via Redis caching. Reduces database queries for connection status checks.
Cache Strategy
- Connection data cached on reads
- Cache invalidated on updates/disconnects
- TTL: 5 minutes (configurable via CACHE_PROVIDER_TTL)
- Database is source of truth
Key Patterns
- provider:conn:{connection_id} -> ProviderConnection entity
Example
class RedisProviderConnectionCache: ... async def get(self, connection_id: UUID) -> ProviderConnection | None: ... # Look up in Redis ... ... ... async def set(self, connection: ProviderConnection) -> None: ... # Store in Redis with TTL ... ...
Source code in src/domain/protocols/provider_connection_cache_protocol.py
Functions¶
get
async
¶
Get provider connection from cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_id
|
UUID
|
Provider connection identifier. |
required |
Returns:
| Type | Description |
|---|---|
ProviderConnection | None
|
ProviderConnection if cached, None otherwise. |
Source code in src/domain/protocols/provider_connection_cache_protocol.py
set
async
¶
Store provider connection in cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
ProviderConnection
|
Provider connection to cache. |
required |
ttl_seconds
|
int | None
|
Cache TTL in seconds. If None, uses CACHE_PROVIDER_TTL from settings. |
None
|
Source code in src/domain/protocols/provider_connection_cache_protocol.py
delete
async
¶
Remove provider connection from cache.
Called when connection is updated, disconnected, or deleted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_id
|
UUID
|
Provider connection identifier. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if deleted, False if not found. |
Source code in src/domain/protocols/provider_connection_cache_protocol.py
exists
async
¶
Check if provider connection exists in cache.
Faster than full get() when only existence check needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_id
|
UUID
|
Provider connection identifier. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if connection exists in cache, False otherwise. |