perf: load the store once and serve reads from memory
T3-17: every get/set/delete re-read and re-parsed the whole file (get 40 ms, set 63 ms at 100k keys). the file is now loaded once into memory; reads return deep copies, set stores the value's json round-trip so memory always equals a reload, and a failed write rolls the in-memory change back. the stale-temp sweep runs once per instance. an external edit after first load is no longer seen (single-process by contract). folds into 1.1.0. Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
1 parent
27b4fcce99
commit
0af38e28dd
2 files changed
+56
-14
No files matched your search
@@ -59,6 +59,16 @@ kv = aiocache("state.json")
|
||||
|
||||
Prefer `AioKV` in new code.
|
||||
|
||||
## Memory model
|
||||
|
||||
The file is read once, on first use, and then served from memory: `get` / `get_all` don't
|
||||
touch the disk, and each `set` / `delete` writes the whole store back atomically. `get` and
|
||||
`get_all` return deep copies, and `set` stores the value's JSON round-trip (exactly what a
|
||||
reload would give back), so mutating a value you passed in or got back never changes the
|
||||
store. Because it is single-process, an edit to the file made by something else after the
|
||||
first read is not seen (and is overwritten by the next write). Orphaned temp files are swept
|
||||
once per instance, on its first save.
|
||||
|
||||
## Durability
|
||||
|
||||
Writes are **atomic**: data is written to a temp file in the same directory and
|
||||
|
||||
Reference in new issue
Block a user