Amazon Developer

as

Settings
Sign out
Notifications
Alexa
Amazon Appstore
Ring
AWS
Documentation
Support
Contact Us
My Cases
Get Started
Design and Develop
Publish
Reference
Support
Skip to main content
AsyncStorageWithKeyScope is an abstraction built on top of AsyncStorage for Vega. It implements the same API with some restrictions: It adds a clearScope() method to be used instead of the clear() method and Vega’s removeValuesForKeysWithPrefix() method. AsyncStorage is an unencrypted, asynchronous, persistent, key-value storage system that is global to the app. It should be used instead of LocalStorage. AsyncStorageWithKeyScope allows you to create instances with a scope prefix string you define. The instance will then transparently prepend all keys with that scope prefix followed by an _ when you make calls to the instance’s APIs and remove the prepended prefix and underscore when returning results. The AsyncStorageWithKeyScope JavaScript code is a facade that provides a clear JavaScript API, real Error objects, and non-multi functions. Each method in the API returns a Promise object. Importing the AsyncStorageWithKeyScope library:
Persisting data:
Fetching data:

Reference

Methods

constructor()

Constructs a AsyncStorageWithKeyScope instance with a designated scope prefix string. Parameters:

getItem()

Fetches an item for a key and invokes a callback upon completion. Returns a Promise object. Parameters:

setItem()

Sets the value for a key and invokes a callback upon completion. Returns a Promise object. Parameters:

removeItem()

Removes an item for a key and invokes a callback upon completion. Returns a Promise object. Parameters:

mergeItem() Vega Not Available

Merges an existing key value with an input value, assuming both values are stringified JSON. Returns a Promise object. NOTE: This is not supported by all native implementations. Parameters: Example:

clear() Vega Not Available

This method is not supported in AsyncStorageWithKeyScope. Use clearScope instead. If you want to erase all data in the store use AsyncStorage.clear() directly. It is generally not recommended to clear data for scopes you don’t own. Parameters:

clearScope()

Remove all values in the store whose keys are prefixed with the scope prefix + ’_’. Parameters:

getAllKeys() Vega Not Available

Gets all keys known to your app; for all callers, libraries, etc. Returns a Promise object. Parameters:

multiGet()

This allows you to batch the fetching of items given an array of key inputs. Your callback will be invoked with an array of corresponding key-value pairs found:
The method returns a Promise object. Parameters: Example:

multiSet()

Use this as a batch operation for storing multiple key-value pairs. When the operation completes you’ll get a single callback with any errors.
The method returns a Promise object. Parameters:

multiRemove()

Call this to batch the deletion of all keys in the keys array. Returns a Promise object. Parameters: Example:

removeValuesForKeysWithPrefix() Vega Not Available

This method will return an error if called on an AsyncStorageWithKeyScope instance. Use clearScope() instead. Parameters:

multiMerge() Vega Not Available

Batch operation to merge in existing and new values for a given set of keys. This assumes that the values are stringified JSON. Returns a Promise object. NOTE: This is not supported by all native implementations. Parameters: Example:
Last modified on May 13, 2026