Add FileCache with atomic writes and TTL
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 52/100
Direzione di ricerca
Start with lettucedetect/detectors/cache.py and the ResponseCache and SyncCacheBase contracts from issues #144 and #145; run uv run --extra dev pytest tests/test_golden_factory_cache_pytest.py -q. Implement and export FileCache with legacy file reading, TTL, locking, and atomic writes, then cover the sync and async behaviors in the acceptance criteria. Done means the cache tests pass, including cancellation, concurrent writes, failed replacement, and construction without disk access.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Parent: #144 · Epic: #126 · Blocked by: #145
Branch from stateless_core; open the PR against it.
Problem
CacheManager creates its directory in the constructor, rewrites the whole file with a plain write_text (a crash mid-write corrupts it), and has no TTL. The lock only covers one process.
Current behavior
lettucedetect/detectors/cache.py:17self.path.parent.mkdir(parents=True, exist_ok=True)in the constructor.cache.py:39and:46self.path.write_text(json.dumps(...))forsetanddelete.- Entries are stored as
key -> value; no expiry.
Steps
- Add
FileCache(path)implementingResponseCache. The constructor touches no disk; the directory is created on the first write. - Read files written by
CacheManager(key to string). An entry with a TTL is stored as{"value": ..., "expires_at": ...}and reads asNoneonce expired. - Write to a temp file in the same directory and
os.replaceit over the file. - Guard with a lock (one process); document that it is single-process.
FileCachebuilds onSyncCacheBase(#145), soaget,aset(withttl_seconds) andadeleterun the blocking file work, including the lock and the atomic rename, in a worker thread and return what the sync methods return. An error raised by the file work (for example a failed write) comes out of the awaited call unchanged.- Run the cache contract suite from #145, plus: a failed write (patch
os.replaceto raise) leaves the previous file readable; aCacheManager-written file reads back; construction touches no disk.
Acceptance criteria
- Each async method equals its sync pair on
FileCache, across the sync/async boundary (written byset, read byaget, and the reverse), andasetwithttl_secondsexpires likeset. -
asyncio.gatherover manyasetcalls for different keys leaves valid JSON with every key; a failed write viaasetleaves the previous file readable and raises from theawait. - Cancelling an
asettask (and await_fortimeout) while the write is in progress leaves the file valid JSON holding the old or the new content, never a partial file, no temporary file is left behind once the thread finishes, and later reads and writes work. - The file work runs off the event loop's thread, and the loop keeps running while it waits.
- All items above covered by tests; threads writing different keys lose none.
- Exported from
lettucedetect.detectors; docstring says single process. - No detector changes; existing tests pass; follows CONTRIBUTING "Errors and logging".
Start here
uv run --extra dev pytest tests/test_golden_factory_cache_pytest.py -q
- Lingua principale
- Python
- Stelle
- 615
- Fork
- 60
- Merge medio
- 1g 8h
- PR unite (30g)
- 10
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di KRLabsOrg/LettuceDetect
-
Stop-hook --min-confidence drops every --llm-model span (missing confidence treated as 0.0), reporting hallucinated answers as cleanForse già presa @Clannad47 l’ha presa 18 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
KRLabsOrg/LettuceDetect#117 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
KRLabsOrg/LettuceDetect#108 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation
Difficoltà 2/5 Mezza giornata Idoneità per principianti 70/100
KRLabsOrg/LettuceDetect#104 ·
I maintainer di solito rispondono entro 1 giorno
-
ready-for-agent
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
KRLabsOrg/LettuceDetect#181 ·
I maintainer di solito rispondono entro 1 giorno
-
ready-for-agent
Difficoltà 5/5 Più di una settimana Idoneità per principianti 22/100
KRLabsOrg/LettuceDetect#180 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di KRLabsOrg/LettuceDetect
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
adafruit/Fruit-Jam-OS#98 ·
-
python triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
microsoft/semantic-kernel#14753 ·
I maintainer di solito rispondono entro 5 giorni
-
area:cli area:configuration documentation priority:low size:small
Difficoltà 1/5 1-3 ore Idoneità per principianti 80/100
RonaldHensbergen/composable-data-stack#1222 ·
I maintainer di solito rispondono entro 1 giorno
-
bug python
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
pvlib/pvlib-python#2939 ·
I maintainer di solito rispondono entro 1 giorno