Skip to content

Latest commit

 

History

History
91 lines (70 loc) · 2.05 KB

storage.md

File metadata and controls

91 lines (70 loc) · 2.05 KB

Storage

The local storage used to store items on the node.

Contents

Constructor

new Storage()


Creates a new Storage instance.

const plexus = require("plexus");

const storage = new plexus.Storage();

Methods

storage.has(key)

  • key: String The key of the item to look for.


Checks if an item with the specified key is already stored.

//  Is an item with the key "key" already stored
storage.has("key");

storage.get(key)

  • key: String The key of the item to look for.


Returns the item with the specified key.

//  Get the item with the key "key" from the storage
storage.get("key");

storage.set(key, value, republish)

  • key: String The key of the item used to retrieve it.
  • value: Object The data to store in the item.
  • republish: Boolean (Default: false) Whether or not the item should be republished after it expires.


Stores an item on the node.

const item = new plexus.Item({key: "key", value: "data", publisher: "id", timestamp: 0});

//  Store an item that wont be republished after it expires
storage.set("key", item, false);

storage.delete(key)

  • key: String The key of the item to delete.


Removes an item from the node.

//  Remove the item with the key "key" from the storage
storage.delete("key");

storage.get_republishable_items()


Returns the list of items to republish after expiration.

//  Get the items to republish
const items = storage.get_republishable_items();

storage.get_items()


Returns the list of items stored.

//  Get the items stored
const items = storage.get_items();