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

@phixid/in-memory-store

v2.0.0

Published

An in-memory data-store intended to be used as a simple cache

Downloads

36

Readme

@phixid/in-memory-store

Installation

npm install @phixid/in-memory-store

Usage

Include the module at the top of your project files as follows.

for Node.js:

const { Store } = require('@phixid/in-memory-store');

for ES6 and above:

import { Store } from '@phixid/in-memory-store';

Basic Store

A basic Store which will expire items after an hour and does not clean itself:

const myPersonalStore = new Store();

Configured Store

There are only two configuration parameters for the Store. The first sets the amount of time (expressed in seconds) before an item in the store will be expired, this defaults to 3600 (an hour). The second will be a time interval (expressed in seconds) at which the store will check all entries and delete all those that have expired, this defaults to 0 (will not clean by default).

API reference

set

Give it a key (string or number) and a value (any type) and it will put it in the Store.

myPersonalStore.set('uniqueKey', 'this is going to be stored');

get

Give it a key and it will retrieve the entry from the Store.

myPersonalStore.get('uniqueKey');

This give you back the value that is stored under the give key. If no entry was found for the given key, or the entry has already expired, this will return null.

delete

Give it a key and it will delete the entry from the Store. This operation does not return anything. The next time you check the Store for an entry with this key, it will not be there.

myPersonalStore.delete('uniqueKey');

memo

This is an all in one operation. Give it a key and a callback function and it will try to get an entry from the Store. If this does not succeed because it does not exist or it has already expired, it will invoke the callback and put the return value in the Store. The return type is the same as the the one from get.

myPersonalStore.memo('uniqueKey', () => 'this will be stored if there is nothing stored already')