User Preferences of Hongmeng Data Management

first choice

User Preferences (Preferences): Provides the persistence capability of lightweight configuration data, and supports the notification capability of subscribing to data changes. Does not support distributed synchronization, and is often used to save application configuration information, user preferences, etc.

Usually used to save application configuration information. The data is saved in the device in the form of text, and the data in the text will be loaded into the memory in full during the application process, so the access speed is fast and the efficiency is high, but it is not suitable for scenarios that need to store a large amount of data.

Operation Mechanism

As shown in the figure, the user program calls the user preference to read and write the corresponding data file through the JS interface. Developers can load the contents of user preference persistent files into the Preferences instance. Each file uniquely corresponds to a Preferences instance. The system will store the instance in memory through the static container until the instance is actively removed from the memory or Delete this file.

img

constraints

  • Key is a string type, which must be non-empty and the length should not exceed 80 bytes.
  • If the value is of string type, it can be empty, and if it is not empty, the length should not exceed 8192 bytes.
  • The memory will increase as the amount of stored data increases, so the amount of stored data should be lightweight. It is recommended that the stored data not exceed 10,000, otherwise a large memory overhead will be incurred.

full source code

import preferences from 

Guess you like

Origin blog.csdn.net/qq_39132095/article/details/132646587