loom.core.cache.repository¶
Functions
|
Auto-infer |
|
Auto-infer |
|
Return T for |
|
Return the domain model class from a projection loader, handling callables. |
Classes
|
Cache-aside wrapper with generational invalidation. |
|
|
|
|
|
- class loom.core.cache.repository.CachedRepository(repository, *, config, cache, dependency_resolver)[source]¶
Bases:
Repository[OutputT,CreateT,UpdateT,IdT],Generic[OutputT,CreateT,UpdateT,IdT]Cache-aside wrapper with generational invalidation.
- Parameters:
repository (Repository[OutputT, CreateT, UpdateT, IdT])
config (CacheConfig)
cache (CacheBackend)
dependency_resolver (DependencyResolver)
- async get_by_id(obj_id, profile='default')[source]¶
Fetch a single entity by its primary key.
- Parameters:
obj_id (IdT) – Primary key of the entity.
profile (str) – Loading profile name for eager-load options.
- Returns:
The entity output struct, or
Noneif not found.- Return type:
OutputT | None
- async get_by(field, value, profile='default')[source]¶
Fetch one entity by arbitrary field.
This path intentionally delegates to the wrapped repository without cache-aside behavior for now. Field-based lookups can target mutable columns and the cache invalidation surface is broader than id-based access; keeping it uncached preserves correctness while the lookup cache policy is designed explicitly.
- async exists_by(field, value)[source]¶
Check existence by arbitrary field.
Existence checks are delegated directly to the wrapped repository to avoid stale negative/positive cache entries on mutable fields.
- async list_paginated(page_params, filter_params=None, profile='default')[source]¶
Fetch a paginated list of entities.
- Parameters:
page_params (PageParams) – Pagination parameters (page and limit).
filter_params (FilterParams | None) – Optional filter criteria.
profile (str) – Loading profile name for eager-load options.
- Returns:
A
PageResultwith the matching items and pagination metadata.- Return type:
PageResult[OutputT]
- async list_with_query(query, profile='default')[source]¶
Fetch entities using a structured
QuerySpec.Supports both offset and cursor pagination, structured filters, and explicit sort directives. The concrete return type depends on
query.pagination:PaginationMode.OFFSET→PageResultPaginationMode.CURSOR→CursorResult
- Parameters:
- Returns:
A
PageResultfor offset queries or aCursorResultfor cursor queries.- Return type:
PageResult[OutputT] | CursorResult[OutputT]
- async create(data)[source]¶
Persist a new entity.
- Parameters:
data (CreateT) – Creation payload struct.
- Returns:
The newly created entity output struct.
- Return type:
OutputT