1e41f4b71Sopenharmony_ci# @system.storage (Data Storage)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci>  **NOTE**
4e41f4b71Sopenharmony_ci>
5e41f4b71Sopenharmony_ci>  - The APIs of this module are no longer maintained since API version 6, and you are advised to use [`@ohos.data.storage`](js-apis-data-storage.md). From API version 9, you are advised to use [`@ohos.data.preferences`](js-apis-data-preferences.md).
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci>  - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci>  
9e41f4b71Sopenharmony_ci>  - The APIs of this module can be used only in the FA model.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## Modules to Import
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci```js
14e41f4b71Sopenharmony_ciimport storage from '@system.storage';
15e41f4b71Sopenharmony_ci```
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## storage.get
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciget(options: GetStorageOptions): void
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ciReads the value stored in the cache based on the specified key.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.Preferences.Core.Lite
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**Parameters**
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci| Name | Type                   | Mandatory| Description      |
28e41f4b71Sopenharmony_ci| ------- | -------------------- | ---- | ---------- |
29e41f4b71Sopenharmony_ci| options | [GetStorageOptions](#getstorageoptions) | Yes  | API configuration.|
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**Example**
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci```js
34e41f4b71Sopenharmony_ciexport default {    
35e41f4b71Sopenharmony_ci  storageGet() {        
36e41f4b71Sopenharmony_ci    storage.get({            
37e41f4b71Sopenharmony_ci      key: 'storage_key',            
38e41f4b71Sopenharmony_ci      success: function(data) {                
39e41f4b71Sopenharmony_ci        console.log('call storage.get success: ' + data);            
40e41f4b71Sopenharmony_ci      },            
41e41f4b71Sopenharmony_ci      fail: function(data, code) {                
42e41f4b71Sopenharmony_ci        console.log('call storage.get fail, code: ' + code + ', data: ' + data);            
43e41f4b71Sopenharmony_ci      },            
44e41f4b71Sopenharmony_ci      complete: function() {                
45e41f4b71Sopenharmony_ci        console.log('call complete');            
46e41f4b71Sopenharmony_ci      },
47e41f4b71Sopenharmony_ci    });    
48e41f4b71Sopenharmony_ci  }
49e41f4b71Sopenharmony_ci}
50e41f4b71Sopenharmony_ci```
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci## storage.set
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ciset(options: SetStorageOptions): void
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ciSets the value in the cache based on the specified key.
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.Preferences.Core.Lite
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci**Parameters**
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci| Name | Type                  | Mandatory| Description      |
63e41f4b71Sopenharmony_ci| ------- | ------------------- | ---- | ---------- |
64e41f4b71Sopenharmony_ci| options | [SetStorageOptions](#setstorageoptions) | Yes  | API configuration.|
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci**Example**
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci```js
69e41f4b71Sopenharmony_ciexport default {    
70e41f4b71Sopenharmony_ci  storageSet() {        
71e41f4b71Sopenharmony_ci    storage.set({            
72e41f4b71Sopenharmony_ci      key: 'storage_key',            
73e41f4b71Sopenharmony_ci      value: 'storage value',            
74e41f4b71Sopenharmony_ci      success: function() {                
75e41f4b71Sopenharmony_ci        console.log('call storage.set success.');            
76e41f4b71Sopenharmony_ci      },            
77e41f4b71Sopenharmony_ci      fail: function(data, code) {                
78e41f4b71Sopenharmony_ci        console.log('call storage.set fail, code: ' + code + ', data: ' + data);            
79e41f4b71Sopenharmony_ci      },        
80e41f4b71Sopenharmony_ci    });    
81e41f4b71Sopenharmony_ci  }
82e41f4b71Sopenharmony_ci}
83e41f4b71Sopenharmony_ci```
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci## storage.clear
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ciclear(options?: ClearStorageOptions): void
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ciClears the key-value pairs from the cache.
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.Preferences.Core.Lite
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci**Parameters**
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci| Name | Type                                       | Mandatory| Description          |
96e41f4b71Sopenharmony_ci| ------- | ------------------------------------------- | ---- | -------------- |
97e41f4b71Sopenharmony_ci| options | [ClearStorageOptions](#clearstorageoptions) | No  | API configuration.|
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ci**Example**
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci```js
102e41f4b71Sopenharmony_ciexport default {    
103e41f4b71Sopenharmony_ci  storageClear() {        
104e41f4b71Sopenharmony_ci    storage.clear({            
105e41f4b71Sopenharmony_ci      success: function() {                
106e41f4b71Sopenharmony_ci        console.log('call storage.clear success.');            
107e41f4b71Sopenharmony_ci      },            
108e41f4b71Sopenharmony_ci      fail: function(data, code) {                
109e41f4b71Sopenharmony_ci        console.log('call storage.clear fail, code: ' + code + ', data: ' + data);            
110e41f4b71Sopenharmony_ci      },        
111e41f4b71Sopenharmony_ci    });    
112e41f4b71Sopenharmony_ci  }
113e41f4b71Sopenharmony_ci}
114e41f4b71Sopenharmony_ci```
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci## storage.delete
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_cidelete(options: DeleteStorageOptions): void
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ciDeletes the key-value pair based on the specified key.
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.Preferences.Core.Lite
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci**Parameters**
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci| Name | Type                                         | Mandatory| Description          |
127e41f4b71Sopenharmony_ci| ------- | --------------------------------------------- | ---- | -------------- |
128e41f4b71Sopenharmony_ci| options | [DeleteStorageOptions](#deletestorageoptions) | Yes  | API configuration.|
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci**Example**
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci```js
133e41f4b71Sopenharmony_ciexport default {    
134e41f4b71Sopenharmony_ci  storageDelete() {        
135e41f4b71Sopenharmony_ci    storage.delete({            
136e41f4b71Sopenharmony_ci      key: 'Storage1',            
137e41f4b71Sopenharmony_ci      success: function() {                
138e41f4b71Sopenharmony_ci        console.log('call storage.delete success.');            
139e41f4b71Sopenharmony_ci      },            
140e41f4b71Sopenharmony_ci      fail: function(data, code) {                
141e41f4b71Sopenharmony_ci        console.log('call storage.delete fail, code: ' + code + ', data: ' + data);            
142e41f4b71Sopenharmony_ci      },        
143e41f4b71Sopenharmony_ci    });    
144e41f4b71Sopenharmony_ci  }
145e41f4b71Sopenharmony_ci}
146e41f4b71Sopenharmony_ci```
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci## GetStorageOptions
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.Preferences.Core.Lite
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci| Name    | Type         | Mandatory| Description                    |
153e41f4b71Sopenharmony_ci| -------- | ---------------- | ---- | ------------------- |
154e41f4b71Sopenharmony_ci| key      | string                               | Yes  | Key of the target data.                                     |
155e41f4b71Sopenharmony_ci| default  | string                               | No  | Default value returned when the specified key does not exist.                             |
156e41f4b71Sopenharmony_ci| success  | (data: any) => void                  | No  | Called to return the result when **storage.get()** is called successfully. **data** is the value indexed by the specified key. |
157e41f4b71Sopenharmony_ci| fail     | (data: string, code: number) => void | No  | Called to return the result when **storage.get()** fails to be called. **data** is the error information, and **code** indicates the error code. |
158e41f4b71Sopenharmony_ci| complete | () => void                           | No  | Called when **storage.get()** is complete.                              |
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci
161e41f4b71Sopenharmony_ci## SetStorageOptions
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.Preferences.Core.Lite
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_ci| Name    | Type               | Mandatory| Description                  |
166e41f4b71Sopenharmony_ci| -------- | ------------------- | ---- | -------------------- |
167e41f4b71Sopenharmony_ci| key      | string                               | Yes  | Key of the data to set.                                |
168e41f4b71Sopenharmony_ci| value    | string                               | Yes  | New value to set. The length must be less than 128 bytes.                             |
169e41f4b71Sopenharmony_ci| success  | () => void                           | No  | Called when **storage.set()** is called successfully.                     |
170e41f4b71Sopenharmony_ci| fail     | (data: string, code: number) => void | No  | Called to return the result when **storage.set()** fails to be called. **data** is the error information, and **code** indicates the error code. |
171e41f4b71Sopenharmony_ci| complete | () => void                           | No  | Called when **storage.set()** is complete.                              |
172e41f4b71Sopenharmony_ci
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci## ClearStorageOptions
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.Preferences.Core.Lite
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci| Name    | Type            | Mandatory| Description                        |
179e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | -------------------- |
180e41f4b71Sopenharmony_ci| success  | () => void                           | No  | Called when **storage.clear()** is called successfully.                |
181e41f4b71Sopenharmony_ci| fail     | (data: string, code: number) => void | No  | Called to return the result when **storage.clear()** fails to be called. **data** is the error information, and **code** indicates the error code. |
182e41f4b71Sopenharmony_ci| complete | () => void                           | No  | Called when **storage.clear()** is complete.                              |
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ci## DeleteStorageOptions
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.Preferences.Core.Lite
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ci| Name    | Type                | Mandatory| Description                 |
190e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------ |
191e41f4b71Sopenharmony_ci| key      | string                               | Yes  | Key of the data to delete.                                            |
192e41f4b71Sopenharmony_ci| success  | () => void                           | No  | Called when **storage.delete()** is called successfully.               |
193e41f4b71Sopenharmony_ci| fail     | (data: string, code: number) => void | No  | Called to return the result when **storage.delete()** fails to be called. **data** is the error information, and **code** indicates the error code. |
194e41f4b71Sopenharmony_ci| complete | () => void                           | No  | Called when **storage.delete()** is complete.                              |
195