Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chia-datalayer-kv-cache

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chia-datalayer-kv-cache

Return Cached Key/Value pairs when requested from Chia DataLayer

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-87.5%
Maintainers
1
Weekly downloads
 
Created
Source

chia-datalayer-kv-cache

A caching module for Chia's datalayer key-value stores. It caches the values of keys in a store, in both memory (using the node-cache package) and on the file system. The package checks for cached values in the memory cache and file system before finally fetching from the datalayer if not found.

The module provides an additional layer of caching for datalayer requests, enhancing speed and efficiency for frequent data retrievals. It leverages both in-memory caching for swift access to recent data and file system caching for longer-term, persistent storage.

Installation

npm install chia-datalayer-kv-cache

Usage

Before using the getValue function, you may optionally use the configure function to specify the hosts and paths for your Chia configuration. If not used, the module will default to certain predefined values.

Promise Chain

const { configure, getValue } = require('chia-datalayer-kv-cache');

configure({
  full_node_host: "https://localhost:8555",
  datalayer_host: "https://localhost:8562",
  wallet_host: "https://localhost:9256",
  certificate_folder_path: "~/.chia/mainnet/config/ssl",
  default_wallet_id: 1,
});

getValue('storeId', 'key')
  .then(value => console.log(value))
  .catch(error => console.error(error));

Async/Await

const { configure, getValue } = require('chia-datalayer-kv-cache');

configure({
  full_node_host: "https://localhost:8555",
  datalayer_host: "https://localhost:8562",
  wallet_host: "https://localhost:9256",
  certificate_folder_path: "~/.chia/mainnet/config/ssl",
  default_wallet_id: 1,
});

async function main() {
  try {
    const value = await getValue('storeId', 'key');
    console.log(value);
  } catch (error) {
    console.error(error);
  }
}

main();

API

configure(newConfig)

Configures the module with the given newConfig. This step is optional, and if not performed, default configuration values will be used.

  • newConfig - A configuration object containing properties:
    • full_node_host
    • datalayer_host
    • wallet_host
    • certificate_folder_path
    • default_wallet_id

getValue(storeId, key)

Attempts to get the value of a key in a store. First checks the memory cache, then the file system cache, and finally the datalayer if the key is not found in the caches. Returns a promise that resolves to the value of the key.

  • storeId - The ID of the store.
  • key - The key to get the value of.

invalidateCache(storeId, key)

Invalidates the cache for a specific key in a store, both in the memory cache and the file system cache.

  • storeId - The ID of the store.
  • key - The key to invalidate the cache of.

Support

If you find this project useful, please consider supporting our work. You can send contributions to the following Chia address:

xch17edp36nd9m5jfcq2sa5qp25ekrrfguvpx05zce35pf65mlvfn4gqyl0434

Your support is greatly appreciated!

Keywords

FAQs

Package last updated on 08 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc