Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]
There are a number of places for Windows Runtime apps to store app data and user data. The right place to store data depends on the scenario and the language you choose to create your app. We outline the full range of storage mediums and highlight scenarios where each medium works best.
Types of app data
There are two kinds of data that apps frequently manage or interact with:
App data
Data that the app itself creates and manages. It is mutable data specific to the internal functions or configuration of a particular app. It includes runtime state, user preferences, reference content (such as the dictionary definitions in a dictionary app), and other settings. App data is tied to the existence of the app and is only meaningful to that app.
User data
Data that the user creates and manages when using an app. It includes document or media files, email or communication transcripts, or database records holding content created by the user. Note that user-selected preferences or app configuration options are considered app data, not user data. User data may be useful or meaningful to more than one app. Often this is data that the user wants to manipulate or transmit as an entity independent of the app itself, such as a document.
Store your Windows Runtime apps app data in data stores that the system provides for that purpose, which are specific to that app and user. The system can then manage these data stores and keep them isolated from other apps and other users. The system preserves these data stores when the user installs an update to the app. The system also removes the contents of these data stores completely and cleanly when the user uninstalls the app. Don't store app data in storage locations intended for user data to circumvent these characteristics.
Because the lifetime of app data stores are tied to the lifetime of the app, don't store user data such as documents or media in data stores intended for app data. Use the user's libraries and Microsoft OneDrive to store this sort of info.
The tables summarize the various data locations available to your app, their limitations, and their recommended uses. Access to some data locations is limited within Windows Runtime apps using JavaScript, depending on the context of the document. All storage size limitations are also constrained by the overall size of the storage medium.
User data
Data location | Available to | Features and limitations | Recommended use |
---|---|---|---|
Libraries accessed by the Windows Runtime StorageFile and file pickers |
|
|
Use for user data that is intended to survive the lifetime of the app or is managed independently by the user. |
|
|
Use for user data that the user wants to access from multiple devices, platforms, or apps. |
|
|
|
Preferred only for scenarios involving upload and download of files. For transfers that continue while the app is not active, use the Windows Runtime BackgroundTransfer from the local context. |
In addition to storage options described in this table, you can also use third-party database and cloud storage solutions.
App data
Data location | Available to | Features and limitations | Recommended use |
---|---|---|---|
|
|
Use for settings and unstructured data files. |
|
|
|
Use for structured and indexed data storage for use solely by JavaScript. It is principally intended for caching scenarios. |
|
|
|
Use for structured and indexed data storage for use by C/C++ or wrapped in a developer-authored Windows Runtime object. |
|
|
|
Use localStorage when you need lightweight storage in a web context and the Windows Runtime is not available. Don't use sessionStorage because it only exists in memory and will not survive app termination. Use it only for momentary storage that is unlikely to be interrupted by the user switching away from the app. |
|
|
|
Preferred only as a place to store transitory app state when the app suspends and is terminated, in order to resume in the same state. |
|
WinJS.Application.local state storage |
|
|
Use for JavaScript that must run in both a web context and local context. |
WinJS.Application.roaming state storage |
|
|
Use for JavaScript that must run in both a web context and local context. |
In addition to storage options described in this table, you can also use third-party database and cloud storage solutions.
Server
When your app interacts with web sites and web services, it can use some other data storage locations:
Data location | Available to | Features and limitations | Recommended use |
---|---|---|---|
|
|
Use when content is read-only, delivered from a web server, and needs to be accessible while the device is offline. While the HTML5 Application Cache can be used to deliver individualized content, it is primarily intended as a caching strategy for offline access to data. |
|
Cookies |
|
|
Use for data that must be shared with each request to a web server. |
Cloud Services, OpenData Services, and Cloud Databases |
|
|
Preferred when working with content that is voluminous, generated by a third party source, or is also displayed on a website as well as in the app. |