Storage Management
Time Capsule uses a layered storage approach with IndexedDB as the primary storage mechanism, localStorage as a fallback, and an in-memory cache for performance.Storage Architecture
SettingsManager Implementation
TheSettingsManager class provides a unified interface for all configuration and state management.
Singleton Pattern
Settings Structure
Settings are organized into logical sections:Version Management
Settings are versioned to handle schema changes and cache invalidation:Storage Adapter
TheStorageAdapter provides a unified API abstracting the underlying storage mechanism.
Synchronous Operations
Legacy Migration
Old settings stored in fragmented keys are automatically migrated:Section Management
Settings are accessed and updated by section:Window Session Persistence
Window positions and states are automatically saved:IndexedDB Usage
WhileSettingsManager currently uses synchronous localStorage operations via the adapter, the architecture supports IndexedDB for future enhancements.
Planned IndexedDB Schema
Cache Management
Memory Cache
SettingsManager maintains an in-memory cache for fast access:XPM Backdrop Cache
Rendered backdrop images are cached to avoid re-parsing expensive XPM files:Performance Considerations
Synchronous Operations
SettingsManager uses synchronous localStorage operations for simplicity and reliability:Batched Updates
Avoid callingsave() in tight loops:
Selective Section Updates
Only update the section that changed:Error Handling
Graceful degradation ensures the application continues working even if storage fails:Storage Quota
Check Available Space
Handle Quota Exceeded
Best Practices
Use Section-Based Access
Use Section-Based Access
Always access settings by section rather than modifying the entire settings object:
Batch Related Changes
Batch Related Changes
Handle Missing Sections Gracefully
Handle Missing Sections Gracefully
Always provide defaults for potentially missing data:
Version Your Schema
Version Your Schema
When making breaking changes to settings structure, increment the version:This triggers automatic cache reset on next load.
Testing Storage
Manual Testing in Console
Clear All Settings
Related Documentation
Architecture
Overall system architecture and design patterns
Window Manager
Window session persistence and restoration
Virtual Filesystem
Future VFS storage integration
Development
Build new features using SettingsManager

