Skip to content

Storage

Wolvan edited this page Feb 9, 2016 · 1 revision

#Storage

A persistent way for plugins to store data.

There are 2 types of storage available to a plugin:

sharedStorage

This storage is shared between all plugins and they all can write and read from there. It is not recommended to put sensitive or important information here, it could be gone or even worse, compromised at any moment. If you want to share information between 2 plugins on the other hand, for example cached objects, this is the storage for you.

It is available through api.sharedStorage.

Private storage

Private storage, as the name implies, is only available to the current plugin. Sensitive information can go here, but there is no easy way to give other plugins access to this storage.

It is available through the 2nd argument of a plugin's load function.

Storage Usage

Both, sharedStorage and private storage, are already initiated instances of Node-Persist and very similar in usage to a browser's localstorage. This gives the basic functions, if you want to know more, head over to Node-Persist's GitHub page

setItem(key, value)

Store a value with a key. Returns a promise that resolves when the key has been saved to disk sucessfully or rejects on error.

getItem(key)

Retrieve a value from the storage. Undefined if value has not been set.

removeItem(key)

Delete a key from storage. Returns a promise that resolves when the key has been removed from disk successfully or rejects on error.

clear()

Delete all stored key-value pairs. Returns a promise that resolves when the files have been removed from disk or rejects on error.

keys()

Returns an array with every key in storage.

##See also API - The API Object for all plugins

Clone this wiki locally