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

@valentech/rocksdb-cache

v1.0.19

Published

Very simple cache based on rocksdb. API: import RocksDbCache from '' const path = './cache' const cache = new RocksDbCache(path) // value can be anything serializable by JSON.stringify await cache.set(key, value) console.log(await cache.get(key))

Downloads

4

Readme

gitter chat npm downloads Coverage Status

RocksDbCache

Note: Unstable API, stay tuned for version 1.1.

This Node.js package provides a simple cache implementation that uses RocksDB as its underlying storage engine. Its API is similar to that of JavaScript's Map, with all methods being asynchronous. However, there are a few minor differences which are highlighted below.

The keys used in this cache must be of type string, while the value can be of any data type. Values are serialized using a custom fork of Sializer with some bug fixes, and then compressed using LZ4. The default Snappy compression of RocksDB is disabled.

This package also includes a Least Recently Used (LRU) read cache that works for both single and bulk operations.

Installation

npm install @valentech/rocksdb-cache

Usage

`import RocksDbCache from '@valentech/rocksdb-cache';

const path = './cache';
const cache = new RocksDbCache(path);

// Value can be anything serializable by Sializer
await cache.set(key, value);
console.log(await cache.get(key));` 

API

constructor(path)

Example: new RocksDbCache('./cache')

cache.set(key, value) or cache.setMany(entries[]<[key,value]>)

Sets the value for the key in the cache. If the value is a promise it will be resolved before it is set.

cache.setMany(entries): Sets the entries in the cache. entries can be any iterable (such as Array, Map, RocksDbCache) which yields a valid entry: [key, value].

cache.get(key) or cache.getMany(keys[]<key>)

Returns the value associated to the key, or undefined if there is none.

cache.getMany(keys): Gets the values associated with keys or undefined if key is not defined. keys can be any iterable (such as Array, Set) which yields a valid key: key.

cache.has(key) or cache.hasMany(keys[]<key>)

Returns a boolean indicating whether an element with the specified key exists or not.

cache.hasMany(keys): Returns booleans indicating whether the elements with the specified keys exist or not. keys can be any iterable (such as Array, Set) which yields a valid key: key.

cache.delete(key) or cache.deleteMany(keys[]<key>)

Removes any value associated with the key. Always returns true, unlike Map.prototype.delete which returns false if there was no value associated with the key.

cache.deleteMany(keys): Removes any values associated with the keys. Always returns true. keys can be any iterable (such as Array, Set) which yields a valid key: key.

cache.clear()

Removes all key-value pairs from the cache.

~~cache.size~~

~~Returns the number of key-value pairs in the cache.~~ Cannot be implemented any faster than iterating through all elements, due to the nature of leveldb.

Async iterator

As all methods are async, there is no Symbol.iterator method. However, you can use an async iterator like this:

for await (let [key, value] of cache) { // Do something }

Example

import RocksDbCache from '@valentech/rocksdb-cache';

async function example() {
  const path = './cache';
  const cache = new RocksDbCache(path);

  const key = 'example';
  const value = { foo: 'bar' };

  await cache.set(key, value);
  console.log(await cache.get(key));

  console.log(await cache.has(key));
  await cache.delete(key);
  console.log(await cache.has(key));

  await cache.clear();
}

example();