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

objstore

v0.1.0

Published

nodejs library for object caching

Downloads

5

Readme

#node-objstore Build Status

JavaScript library for storing objects.

##NPM

npm install objstore --save

##Configuration

Storage.create accepts a configuration object:

default values:

Storage.create({
    // remove 100 values if free is called or size is reached.
    perFree: 100,
    // storage can hold 1000 values
    size: 1000,
    // expire values after 60 secs
    expire: 60000
});

If expire equals -1 it will not automatically remove values.

##Examples

###Storing and accessing a value

var Storage = require('objstore');
var myStorage = Storage.create();

// store myValue on foo
myStorage.store('foo', myValue);

// find at foo stored value
myStorage.find('foo')

###Using global storage object

var Storage = require('objstore');
Storage.global();

var store1 = Storage.create();
var store2 = Storage.create();

// store1 equals store2

##Methods

Storage

  • Storage.global(conf) lets each .create() return the same instance.
  • Storage.local() lets each .create() return a new storage instance.
  • Storage.create(conf) creates a storage instance. If .local() was called it will use opts to configure the new instance.

Storage.create() instance

  • find(key) tries to find a stored value using the given key. If nothing is found it returns undefined
  • store(key, value, expiresIn) stores/updates a value using the given key. If expiresIn is negativ it won't expire values automatically.
  • remove(key) removes a value from the storage
  • clear() removes all values from teh storage
  • size() returns the number of stored values
  • free(amount) removes amount oldest values
  • all() returns an array with all stored values
  • on(topic, callback) subscribes to topic with a callback
  • beginStoreProperties() to disable the size check before adding values. This can be useful if you want to add multiple values to the store and handle the size after all of them are added.
  • endStoreProperties() to enable the size check before adding values. This will also free if the size is greater than config.size.

##TODO

  • implementation without setTimeout
  • Example
  • Documentation
  • Benchmark
  • ES6 Map/Proxy

##How

objstore uses an object to store values under a given key. The stored value is wrapped in an object that contains a timestamp, an interval id and a the value.

To avoid too many stored objects there is an option to limit the amount of stored values. If the limit is reached or the free method is called, the oldest values are removed from the storage.

Finding the oldest values is accomplished using a second object that uses the timestamp of stored objects as keys and keys of stored objects as values. Using the Object.keys method an array is created that contains all timestamps. Object.keys automatically sorts the array items. The array.slice method is used to cut a chunk of the sorted expiration map. The new array is used too loop through all timestamps and get the main storage keys to remove them.

The expiration is implemented using the setTimeout method.

##Documentation

For the documentation see makepanic.github.io/node-objstore/