my.setStorageSync

Store synchronously the data in the specified key in the local cache.

Supported types of mini programs: DSL

This is a synchronous interface.

Sample Code

copy
my.setStorageSync({
  key: 'currentCity',
  data: {
    cityName: 'London',
    adCode: '330100',
    spell: ' London',
  }
});

Parameters

PropertyType

Required

Description
keyStringYesCache data key.
dataObjectYesData to be cached.

Error code

Error code

Error message

Further action

2

Required parameter is empty

Make sure the data type of the key parameter is correct and the value is not empty.

12

Maximum storage

The data storage limit for a single mini program is 10 MB. Use the my.removeStorage JSAPI to clear unnecessary data.

13

Storage failure

Failed to store the data in the local cache. Please try again later.

14

Data length overrun

The maximum data size allowed for a single key is 200 KB. Please reduce the data length or split it into multiple keys.