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

rs-mem-cache

v0.0.5

Published

Heavily a WIP

Downloads

4

Readme

rs-mem-cache

Heavily a WIP

Will require Rust to be installed to run for development

https://www.rust-lang.org/learn/get-started

Usage

This package exposes a Cache using the Rust LRU Cache Library

https://github.com/jeromefroe/lru-rs

Mostly a performance experiment to see if offloading memory management from NodeJS into Rust has any benefits in apps that use lots of caching but don't want heavy IPC

Based on the test suite you've provided for the SyncCache class, here's a README outline that explains how to use the SyncCache library. This README includes sections on installation, basic usage, handling different data types, and working with multiple items.

Installation

  1. Add rs-mem-cache to your project dependencies using yarn or npm.
yarn add rs-mem-cache
# or
npm install rs-mem-cache

Basic Usage

The SyncCache class allows you to set, get, and manage cache entries with ease. Here's a quick start guide:

import { SyncCache } from 'rs-mem-cache';

// Initialize cache with a specified capacity
const cache = new SyncCache(1000000); // Capacity of 1,000,000 items

// Set a value
cache.set('key', 'value');

// Retrieve a value
const value = cache.get('key'); // Returns 'value'

// Check for an unknown key
const unknown = cache.get('unknown'); // Returns null

Handling Different Data Types

The cache, like its underlying rust impl works with string values, you can handle different data types by serializing them to a string format.

Storing Numbers

To store numbers, convert them to strings or serialize them:

const key = 'numberKey';
const value = 123;

// Store as a string
cache.set(key, value.toString());

// Retrieve and parse
const storedValue = parseInt(cache.get(key), 10);

Working with JSON

For more complex data types like objects or arrays, you can use JSON serialization:

const key = 'objectKey';
const value = { a: 1, b: 2 };

// Serialize and store
cache.set(key, JSON.stringify(value));

// Retrieve and parse
const storedValue = JSON.parse(cache.get(key));

Setting Multiple Items

You can set multiple items at once using the mset method:

// Prepare multiple key-value pairs
const items = [
  ['key1', 'value1'],
  ['key2', 'value2'],
];

// Set multiple items
cache.mset(items);

// Retrieve to verify
console.log(cache.get('key1')); // Outputs 'value1'
console.log(cache.get('key2')); // Outputs 'value2'

Contributing

This is my first experiment with Rust, I would like to implement the following and am happy to get help in doing so:

  • Expose the remaining functions
  • Make functions async so it uses tokio async mutex

Make sure rust is installed, run npm install and it should work with a npm run build and npm run test

To make a release run

npm version patch
git push --follow-tags