npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chia-datalayer-kv-cache

v1.0.7

Published

Return Cached Key/Value pairs when requested from Chia DataLayer

Downloads

12

Readme

chia-datalayer-kv-cache

chia-datalayer-kv-cache is an NPM package designed to interact with Chia's data layer and provide a caching mechanism to enhance performance. It primarily offers methods to get and invalidate cached values, either from memory cache or from a filesystem cache.

The package uses the NodeCache library for in-memory caching, and filesystem caching is achieved by storing values in a designated cache directory on disk. The package also includes support for Chia's data layer with the help of the chia-datalayer-wrapper package.

Installation

npm install chia-datalayer-kv-cache

Usage

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

// Optional: Configure the module
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,
});

// Get a value from cache or datalayer
getValue({ id: "storeId", key: "key" })
  .then((value) => {
    console.log(value);
  })
  .catch((error) => {
    console.error(error);
  });

// Get all keys for a storeId from cache or datalayer
getKeys({ id: "storeId" })
  .then((value) => {
    console.log(value);
  })
  .catch((error) => {
    console.error(error);
  });

// Invalidate a cache entry
invalidateCache("storeId", "key");

Using async/await:

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

async function main() {
  configure({
    // your configuration here...
  });

  const value = await getValue({ id: "storeId", key: "key" });
  console.log(value);

  const keys = await getKeys({ id: "storeId" });
  console.log(keys);

  invalidateCache("storeId", "key");
}

main().catch((error) => console.error(error));

If no configuration is provided using configure(), the module uses default values which can be found in the defaultConfig.js file.

API

configure(newConfig)

Merge the provided configuration object with the current configuration.

getValue({ id: storeId, key })

Fetches the value associated with the provided storeId and key from the cache. If it's not present in the cache, it fetches from the Chia's data layer, storing the value in the cache for future retrieval.

getKeys({ id: storeId })

Fetches all keys for the given storeId from the cache. If they're not present in the cache, it fetches from the Chia's data layer, storing the keys in the cache for future retrieval.

invalidateCache(storeId, key)

Invalidates a cache entry. If only the storeId is provided, it invalidates all entries related to that store. If both storeId and key are provided, it invalidates the specific cache entry.

Cache AutoInvalidation

This package uses the chia-datalayer-update-notifier package to watch the store for updates and it will automatically invalidate the cache when an update is detected.

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!