Skip to main content

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

The SettingsManager 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:
When the version changes, all cached settings are cleared and reset to defaults. This prevents issues from schema changes.

Storage Adapter

The StorageAdapter 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

While SettingsManager 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:
Synchronous storage operations are acceptable here because:
  1. Settings data is small (typically < 50KB)
  2. Operations are infrequent (user actions only)
  3. Blocking UI briefly is better than race conditions
  4. localStorage is much faster than IndexedDB for small data

Batched Updates

Avoid calling save() 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

Always access settings by section rather than modifying the entire settings object:
Always provide defaults for potentially missing data:
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

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