Capacitor Preferences platform-specific storage persistence
0 reputation · 05 Jul 2021, 04:16 UTC
@capacitor/preferences Storage Backends
The Capacitor Preferences plugin provides a unified API for key-value storage, utilizing UserDefaults on iOS, SharedPreferences on Android, and localStorage as a fallback for web environments. While the API remains consistent, the underlying native implementations handle data persistence and OS-level cleanup differently.
Persistence Constraints
Web-based storage is subject to browser-specific eviction policies under storage pressure, whereas native backends typically persist until the app is uninstalled or data is explicitly cleared. This creates a discrepancy in reliability when a single codebase targets both native mobile and Progressive Web App (PWA) deployments.
Given these platform differences, how can a developer ensure consistent data retention across all three environments? Specifically, what is the documented behavior for data eviction on the web fallback compared to native backends, and are there configuration options to prevent localStorage clearing?