feat: add GraphCache β write-through MemoryStore with SQLite persistence#79
Merged
jamestexas merged 2 commits intomainfrom Mar 12, 2026
Merged
feat: add GraphCache β write-through MemoryStore with SQLite persistence#79jamestexas merged 2 commits intomainfrom
jamestexas merged 2 commits intomainfrom
Conversation
Generic cache extracted from x-ray's SchemaCache pattern. Wraps MemoryStore with sync.RWMutex and automatic ExportSQLite on every mutation. Provides tree manipulation helpers (PutDir, PutFile, AppendChild, RemoveChild, ClearChildren) and a Store() escape hatch for batch operations. 14 tests covering CRUD, SQLite reload, dedup, concurrency, and the escape hatch pattern.
Batch acquires the write lock, calls the provided function with the underlying MemoryStore, then persists once. This enables complex operations (backup β clear β rebuild β restore) to run atomically without exposing intermediate state to concurrent readers, and with a single SQLite write instead of N individual ExportSQLite calls. Motivated by x-ray's SchemaCache.PutZones which does 30-50 store operations under one lock β individual PutDir/PutFile/AppendChild calls would break both atomicity and persistence efficiency.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
graph.GraphCacheβ a thread-safeMemoryStorewrapper with automatic SQLite write-through persistence viaExportSQLite/ImportSQLitePutDir,PutFile,AppendChild,RemoveChild,ClearChildren, plus read methods and aStore()escape hatch for batch operationsSchemaCachepattern (808 LOC domain-specific cache) β this is the generic ~240-line core that any mache consumer can reuseMotivation
x-ray's
internal/api/schemacache.gomixes generic caching logic (mutex + MemoryStore + persist-on-write) with domain-specific code (URL keys, fingerprints, NavSections). Extracting the generic part into mache means:GraphCachewith its domain logic instead of reimplementing the plumbingAPI
Test plan
graph/cache_test.gocovering CRUD, SQLite persistence reload, dedup, concurrency, escape hatchgraph/tests still passgo test -race)π€ Generated with Claude Code