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

node-ipc-store

v1.0.8

Published

node-ipc-based freely configurable shared storage.

Downloads

21

Readme

node-ipc-store

node-ipc-based freely configurable shared storage. Memory, file and MySQL accessors included.

Installation

npm i node-ipc-store

Server

Configuration

{
	ipc: { // node-ipc config
		id: "node-ipc-store",
		silent: true
	},
	accessor: new Accessor, // accessor used to restore values in the cache
	cachedValueTtl: 3600 * 1000, // values are removed from the cache if the time has expired (use -1 as infinity)
	cachedValueTtlTestInterval: 60 * 1000,
	startupTimeout: 5 * 1000 // server shuts down if the time after startup has expired and the clients have not connected (use -1 as infinity)
}

Example

const {Server} = require("node-ipc-store");

const server = new Server;

Simple accessor

This accessor is used for in-memory caching - it doesn't actually store values anywhere.

Configuration

{
	decorate: undefined, // f(server, key, value, onResult) - use to decorate the value before return
	actions: {} // name -> f(server, value, onResult)
}

FileAccessor

This accessor stores values in files.

Configuration

{
	decorate: undefined, // f(server, key, value, onResult) - use to decorate the value before return (do not modify the value if an error occurred)
	actions: {}, // name -> f(server, value, onResult)
	path: "./dat/" // the values are stored in the path/key files
}

MysqlAccessor

This accessor stores values in a MySQL DB. For tables without specified rule, this accessor uses default rules with keys like: some_table/some_key_field_name/some_key_field_value/some_field_name (for one field) or some_table/some_key_field_name/some_key_field_value (for all fields).

Configuration

{
	decorate: undefined, // f(server, key, value, onResult) - use to decorate the value before return (do not modify the value if an error occurred)
	actions: {}, // name -> f(server, value, onResult)
	connection: undefined,
	rules: {} // table -> sql, values(key), parse(results), where parse return [success, value]
}

Router

This accessor is used for routing between multiple accessors by key/name prefix.

Configuration

{
	accessors: {} // prefix -> accessor
}

Client

Configuration

{
	ipc: { // node-ipc config
		id: "node-ipc-store",
		retry: 1000,
		silent: true
	},
	serverPath: "./server.js", // clients automatically start the server (use undefined to prevent autostart)
	defaultRequestTtl: 5 * 1000, // requests are considered failed if the time has expired (use -1 as infinity)
	requestTtlTestInterval: 1 * 1000
}

Methods

get

get(key, onResult, ttl = this.#config.defaultRequestTtl, hash)

Used to get the value from the cache or via the accessor (if the value is not in the cache). The value is not actually passed if the hashes are the same. The value is always passed if the hash is undefined or the accessor does not support hashing.

set

set(key, value, onResult, ttl = this.#config.defaultRequestTtl)

Used to set the value.

remove

remove(key, onResult, ttl = this.#config.defaultRequestTtl)

Used to remove the value.

resetCache

resetCache(key, onResult, ttl = this.#config.defaultRequestTtl)

Used to remove the value from the cache.

action

action(name, value, onResult, ttl = this.#config.defaultRequestTtl)

Used to perform some actions on the server.

setServerPath

setServerPath(serverPath)

Used to set the path to the server.

shutdownServer

shutdownServer()

Used to shutdown the server.

Example

const {Client} = require("node-ipc-store");

const client = new Client;

const actions = [
	() => client.set("x", 42, (success, details) => {
		console.log("set x:", success, details);
	}),

	() => client.get("x", (success, details) => {
		console.log("get x:", success, details);
	}),

	() => client.remove("x", (success, details) => {
		console.log("remove x:", success, details);
	})
];

const exec = () => {
	const action = actions.shift();
	if (action) {
		action();
		setTimeout(exec, 2000); // sending requests with pauses
	} else {
		console.log("done");
		process.exit();
	}
};

exec();

Output

c:\npm\node-ipc-store\examples>cache\node client.js
Client: disconnected
Client: fork
Client: connected
set x: true undefined
get x: true 42
remove x: true undefined

For a complex example, visit examples/mysql-ext/server.js.