Migrate cache service from localStorage to IndexedDB#84
Merged
IvanildoBarauna merged 1 commit intomainfrom Mar 3, 2026
Merged
Conversation
Replace the BrowserCache localStorage implementation with IndexedDB to reduce backend requests. IndexedDB offers much larger storage quota (GB vs ~5MB) and persists across browser sessions just like localStorage, but with better capacity for caching API responses long-term. Changes: - Rewrite cacheService.ts using IndexedDB with async methods (Promise-based) - All BrowserCache methods are now async: get, set, remove, clearAll, clearExpired, getStats - same class name and exports preserved - clearPortfolioCache() is now async to ensure cache is cleared before logging - Update all 4 data-fetching hooks to await async cache calls - Add fake-indexeddb dev dependency for test environment (jsdom lacks IndexedDB) - Rewrite unit and integration tests: async/await, IndexedDB reset between tests, shared insertRawEntry helper for edge-case scenarios - Retain 30-day TTL, portfolio_cache_ key namespacing, and cache invalidation endpoint compatibility (window.clearPortfolioCache still works) All 65 tests pass (49 cache tests + 16 other tests). Co-authored-by: Ivanildo Barauna de Souza Junior <ivanildo.jnr@outlook.com> https://claude.ai/code/session_01CWajAL77hbhWSCYir3UKMS
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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
Migrated the BrowserCache service from localStorage-based implementation to IndexedDB, providing significantly larger storage capacity (GB vs ~5MB) while maintaining the same API surface and type safety.
Key Changes
Core Implementation
Storage Backend: Replaced localStorage with IndexedDB for the cache service
openDB()helper to manage IndexedDB connections with proper initializationkeyas keyPath for efficient lookupsAPI Changes: Made all BrowserCache methods async
get<T>(key)→async get<T>(key): Promise<T | null>set<T>(key, data, ttl)→async set<T>(key, data, ttl): Promise<void>remove(key)→async remove(key): Promise<void>clearAll()→async clearAll(): Promise<void>clearExpired()→async clearExpired(): Promise<void>getStats()→async getStats(): Promise<CacheStats>clearPortfolioCache()→async clearPortfolioCache(resourceType?): Promise<void>Data Structure: Updated cache entry format for IndexedDB
keyfield (required for keyPath)data,timestamp, andexpiresAtfieldsHook Updates
Updated all data-fetching hooks to await cache operations:
useExperience.tsuseEducation.tsuseProjects.tsuseSocialLinks.tsTesting Infrastructure
fake-indexeddbpolyfill for Node.js test environmentresetDB()andinsertRawEntry()utilities for test isolationRemoved Features
Notable Implementation Details
db.close()in all code pathsclearAll(),clearExpired(), andgetStats()operationsisBrowser()check for IndexedDB availabilityhttps://claude.ai/code/session_01CWajAL77hbhWSCYir3UKMS