Skip to content

feat: Migrate cache from data.json to IndexedDB - #179

Merged
nathonius merged 2 commits into
nathonius:mainfrom
jdevera:feat/indexeddb-cache
Aug 6, 2026
Merged

feat: Migrate cache from data.json to IndexedDB#179
nathonius merged 2 commits into
nathonius:mainfrom
jdevera:feat/indexeddb-cache

Conversation

@jdevera

@jdevera jdevera commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #174

This PR moves the API response cache from data.json (Obsidian's synced settings file) into IndexedDB, which stays local to the device.

What changed

  • Cache storage: Replaced the in-memory Record-based RequestCache with an IndexedDB-backed store using the idb library (~1KB, widely used by 20+ Obsidian plugins). An in-memory layer is kept on top for fast synchronous reads.
  • Removed periodic save: Since IndexedDB persists on write, the cacheIntervalSeconds setting and the setCacheInterval() timer are no longer needed.
  • One-time migration: On first load after upgrading, existing cache entries in data.json are imported into IndexedDB, then cleared from data.json (along with the legacy cacheIntervalSeconds key).
  • All existing cache behavior preserved: TTL cleanup on startup (maxCacheAgeHours), request freshness checks (minRequestSeconds), HTTP conditional requests (ETag/Last-Modified), and the "Clear cache" button in settings all work as before.

What I tested

  • Tested locally in Obsidian: migration message in console, cache entries visible in DevTools > Application > IndexedDB
  • Verified data.json no longer contains cache or cacheIntervalSeconds after migration
  • Verify GitHub links render from cache after Obsidian restart
  • Verify "Clear cache" button in settings empties IndexedDB

Move the API response cache out of Obsidian's data.json (which gets
synced) into IndexedDB (which stays local). This prevents cache data
from bloating sync and keeps device-specific data where it belongs.

- Replace in-memory Record-based RequestCache with IndexedDB-backed
  storage using the idb library, with an in-memory layer for fast
  synchronous reads
- Remove periodic cache save interval (cacheIntervalSeconds setting)
  since IndexedDB persists on write
- Add one-time migration: existing data.json cache entries are imported
  into IndexedDB, then cleared from data.json along with the legacy
  cacheIntervalSeconds setting
- Preserve all existing cache behavior: TTL cleanup on startup
  (maxCacheAgeHours), request freshness checks (minRequestSeconds),
  and HTTP conditional requests (ETag/Last-Modified)
@jdevera
jdevera force-pushed the feat/indexeddb-cache branch from 874dd32 to a1ed9bf Compare April 18, 2026 23:07
@sonarqubecloud

Copy link
Copy Markdown

@nathonius nathonius left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once again, looks great. And again, sorry for the delay.

@sonarqubecloud

sonarqubecloud Bot commented Aug 6, 2026

Copy link
Copy Markdown

@nathonius
nathonius merged commit 217cc2e into nathonius:main Aug 6, 2026
2 checks passed
@nathonius

Copy link
Copy Markdown
Owner

@all-contributors please add @jdevera as a contributor for code

@allcontributors

Copy link
Copy Markdown
Contributor

@nathonius

I've put up a pull request to add @jdevera! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: cache migration to IndexedDB from settings JSON

2 participants