Engine/MemoryCache: Stage 1 improvements (RFC #2647) #2649
+283
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces the first round of improvements for the new in-memory cache in LiteDB 5.
Goal: make the cache more predictable, configurable, and robust under heavy concurrent load, while keeping all tests stable.
Key changes
Volatile on scalar tuning fields
_maxFreePages
,_cleanupBatchSize
,_extends
asvolatile
to improve visibility across threads._idleBeforeEvict
,_minCleanupInterval
) remain asTimeSpan
(structs cannot bevolatile
).Safer on-demand cleanup triggers
NewPage()
andGetWritablePage()
to avoid interfering with segment extension andUniqueID
sequencing (fixes the failingCache_UniqueIDNumbering
test).GetReadablePage()
(hot read path),DiscardPage()
(when pages are freed),Clear()
(manual cleanup),_maxFreePages
(forced).SemaphoreSlim
) with batched eviction and idle policy.Accurate comments & readability
Cleanup()
docs to reference_cleanupBatchSize
and_idleBeforeEvict
(instead of stale constants).Profiles groundwork
CacheProfile { Mobile, Desktop, Server }
andApplyProfile(profile)
.// TODO
marker left in code).Motivation
LiteDB is often used in embedded scenarios with high concurrency and limited resources.
These changes make cache tuning safer and clearer without adding locking overhead or altering public APIs.
Impact
Related
Next steps
CacheProfile
selection via engine parameter (Etapa 2).Checklist
dev-staging
Notes for reviewers