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

kosyak

v0.0.5

Published

Distributed in-memory cache written in Node.js.

Downloads

8

Readme

kosyak

NPM version

Distributed in-memory cache store written in Node.js.

All the data is stored on different nodes which are connected between each other with simple TCP/IP JSON-messaging.

Attention! Data consistency is not guaranteed since if one node dies all the data stored in it is gone.

Installation

npm install kosyak --save

Usage

'use strict'
var assert = require('assert')
var Node = require('kosyak')

var firstNode = new Node({
  host: '127.0.0.1',
  port: 13390
}).init(/* callback(err) */)

var secondNode = new Node({
  master: {
    host: '127.0.0.1',
    port: 13390
  }
}).init(/* callback(err) */)

// after all initialized
firstNode.set('key', 123, function(err, value) {
  assert.strictEqual(value, 123)

  secondNode.get('key', function(err, value) {
    assert.strictEqual(value, 123)

    firstNode.stop(/* callback */)
    secondNode.stop(/* callback */)
  })
})

API

Node

Base class which provides functionality to work with whole store.

Node(options)

Create Node instance.

Arguments

  • options object - Client options.
    • addr string - Address or host to bind to.
    • port number - Port to bind to.
    • master object - Address/port of master node.
      • addr string
      • port number
    • socket object - Options passed to net.Socket constructor.
    • server object - Options passed to net.Server constructor.
    • stringify boolean - If data should be stored as JSON string. Defaults to false.
    • fetch(key, callback) function - Fetch function. Read more about it in Node#get method description.
    • connectDelay number - Delay between attempts to connect remote node (ms). Grows in arithmetic progression. Defaults to 2000.
    • connectAttempts number - Max # of attempts to connect to remote node. Defaults to 3.

void eachEntry(iterator)

Iterate through each local entry

Arguments

  • iterator function - Iterator. Should accept following arguments: (value, key, entry).

void get(key, callback)

Get or fetch value by key. Get operation works using following algorithm:

  1. Check if entry is stored locally. If local entry is found it retured. Otherwise go to step 2.
  2. Check if entry is stored in one of the remote nodes. If so get request is sent to remote node. Otherwise go to step 3.
  3. If fetch function is specified in Node constructor options fetch(key, done) is called, then value is set locally and other nodes are notified. Otherwise null is returned.

Arguments

  • key string
  • callback(err, value) function - Callback function.

void init(callback)

Start server and connect to master node if it's specified in options.

Arguments

  • callback(err) function - Callback function.

void remove(key[, callback])

Remove local entry.

Arguments

  • key string
  • callback(err) function - Callback function.

void set(key, value[, callback])

Set value locally and notify other nodes.

Arguments

  • key string
  • value * - Value to be set.
  • callback(err, value) - Callback function.

object stats([callback])

If callback is specified node requests stats from all the nodes and returnes them as callback first argument. If not specified stats for node returned.

Arguments

  • callback(nodesStats) function - Callback function.

void stop([callback])

Stop node and disconnect from all the remote nodes.

Arguments

  • callback() function - Callback function.

FAQ

Why this cache store it's called so?

My friend has a cat called Kosyak. And this cat is crazy. Why not call module so?