1# Preferences Overview 2 3Preferences are used to implement quick access and persistence of the data in the `key-value` structure. 4 5After an application obtains a **Preferences** instance, the data in the instance will be cached in the memory for faster access. 6 7The cached data can also be written to a text file for persistent storage. Since file read and write consume system resources, you are advised to minimize the frequency of reading and writing files. 8 9You do not need to care about the implementation of the database locking mechanism. 10 11## Basic Concepts 12 13- **Key-value structure** 14 15 A type of data structure. The `Key` is the unique identifier for a piece of data, and the `Value` is the specific data being identified. 16 17- **Non-relational database** 18 19 A database not in compliance with the atomicity, consistency, isolation, and durability (ACID) properties of relational data transactions. The data in a non-relational database is independent. The database that organizes data in the `key-value` structure is a non-relational database. 20 21## Working Principles 22 231. An application can load data from a **Preferences** persistent file to a **Preferences** instance. The system stores the **Preferences** instance in the memory through a static container. Each file of an application or process has only one **Preferences** instance in the memory, till the application removes the instance from the memory or deletes the **Preferences** persistent file. 242. When obtaining a **Preferences** instance, the application can read data from or write data to the instance. The data in the `Preferences` instance can be flushed to its **Preferences** persistent file by calling the **flush()** method. 25 26**Figure 1** Working mechanism 27 28 29 30## Constraints 31 32- **Preferences** instances are loaded to the memory. To minimize non-memory overhead, the number of data records stored in a **Preferences** instance cannot exceed 10,000. Delete the instances that are no longer used in a timely manner. 33- The `Key` in key-value pairs is of the string type. It cannot be empty or exceed 80 bytes. 34- The `Value` of the string type in key-value pairs can be empty, but cannot exceed 8192 bytes if not empty. 35