๐Ÿ“ฆ EasyTempStorage for ZeppOS

Description

EasyTempStorage is designed for temporary, in-memory data storage. It's ideal for data that needs to be accessible throughout the app's lifecycle but not persisted between sessions. This makes it perfect for session data, temporary caches, or any scenario where data persistence beyond the app's current session is unnecessary.

To install the library run (from the root of your project)

npm i @silver-zepp/easy-storage

[ ๐Ÿ“ Download examples ]

[ ๐Ÿ“ Class Map ]

[ ๐Ÿ“ API Reference ]

[ โฌ…๏ธ Back to Index ]

Example

import { EasyTempStorage } from "@silver-zepp/easy-storage";
const temp = new EasyTempStorage();

temp.setKey("session", { token: "abc123" });
console.log(temp.getKey("session"));

๐Ÿ“ EasyTempStorage Class Map ย 

๐Ÿ“ EasyTempStorage API Reference

constructor()

Initializes the temporary storage instance.

Examples

const temp = new EasyTempStorage();

setKey(key, value)

Stores a value associated with a key in memory. The value is kept until the application is closed or explicitly removed.

Parameters

Examples

temp.setKey('session', { user: 'John Doe', token: 'abc123' });

getKey(key)

Retrieves the value associated with the specified key from the storage.

Parameters

Examples

console.log(temp.getKey('session'));

Returns

any - The value associated with the key, or undefined if not found.

hasKey(key)

Checks if the specified key exists in the storage.

Parameters

Examples

console.log(temp.hasKey('session')); // true or false

Returns

boolean - True if the key exists, false otherwise.

removeKey(key)

Removes the specified key and its value from the storage.

Parameters

Examples

temp.removeKey('session');

getAllKeys(stringify = false)

Retrieves all keys stored in the storage, optionally stringified.

Parameters

Examples

console.log(temp.getAllKeys());
console.log(temp.getAllKeys(true));

Returns

string | array - The keys as a JSON string if stringify is true, or as an array if false.

deleteAll()

Removes all keys and their values from the storage.

Examples

temp.deleteAll();

printAllKeys()

Prints all keys and their associated values to the console.

Examples

temp.printAllKeys();