fastrag.ingestion.cache.sqlite#
SQLite-backed CacheStore.
One file and no server, for a caller who does not want to run Postgres.
Built on the standard-library sqlite3 module, so it adds no
dependency.
The layout mirrors fastrag.ingestion.cache.schema: a bucket per
cache id, a snapshot per item of a bucket’s output, and a record per
logical id carrying the garbage-collection clock. __aenter__ creates the
tables if they are absent.
sqlite3 is blocking, so every operation runs as one transaction on a
dedicated worker thread that owns the connection. Operations from one
instance are therefore serialized; separate processes may share the file,
since the database runs in WAL mode and waits out a writer’s lock.
Classes
|
Cache pipeline sources and documents in a local SQLite file. |
- class fastrag.ingestion.cache.sqlite.SQLiteCache(*, path, timeout=30.0)[source]#
Bases:
CacheStoreCache pipeline sources and documents in a local SQLite file.
async with SQLiteCache(path=".fastrag/cache.sqlite") as cache: sources = SitemapCrawler(url=SITEMAP_URL, cache=cache)
- Parameters:
path (str | os.PathLike[str]) – The database file. Created, along with missing parent directories, on
__aenter__.":memory:"keeps the cache in memory for the lifetime of theasync withblock.timeout (float) – Seconds to wait for another process’s write lock before an operation fails with
TransientCacheError.
- async get_source_entries(source_cache_id)[source]#
See
get_source_entries().
- async get_source_headers_many(cache_ids)[source]#
Retrieve only identities, validators and routing metadata for indexing.
- async get_bucket_sources(source_cache_id, source_ids)[source]#
See
get_bucket_sources().
- async put_source_entries(source_cache_id, sources)[source]#
See
put_source_entries().
- async get_document_entries_many(document_cache_ids)[source]#
Fetch document buckets in one transaction.
- async get_document_headers_many(cache_ids)[source]#
Retrieve snapshot identifiers and routing metadata without large payloads.
- async clear_sources()[source]#
See
clear_sources().- Return type:
- async clear_documents()[source]#
See
clear_documents().- Return type:
- async delete_sources(source_ids)[source]#
See
delete_sources().
- async delete_documents(source_ids)[source]#
See
delete_documents().
- async collect_garbage(max_age)[source]#
See
collect_garbage().