Replace SQLite with in-memory pickle-based index #1
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 replaces the SQLite-based index with a simpler in-memory pickle-based index, reducing complexity while maintaining performance and improving crash recovery.
Changes
Core Migration
index.db(SQLite) →index.pkl(pickled Python dict)sqlite3imports and SQL queriesKey Files Modified
src/torchcachex/backend.py- Complete rewrite of index management_load_index()- loads pickle or rebuilds from segments_save_index()- atomic pickle persistence_rebuild_index_from_segments()- crash recoverytests/test_backend.py- Added new tests for index persistence and rebuildtests/test_recovery.py- Updated to test pickle-based recoverytests/test_edge_cases.py- Fixed references to new index attributesDocumentation Updates
__init__.pyandbackend.pyCode Quality
Benefits
✅ Simpler architecture
✅ Faster lookups
✅ Better crash recovery
✅ More compact storage
Trade-offs
Testing
All tests passing:
```
======================== 72 passed, 2 skipped in 0.96s =========================
```
Breaking Changes
No user code changes required - the migration is transparent.
Performance
No regression in performance:
🤖 Generated with Claude Code