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 🙏

© 2025 – Pkg Stats / Ryan Hefner

astore

v1.1.0

Published

An ephemeral shared store for DAOs

Readme

Astore

A store that sits on top of your DAO to save your application from making unecessary calls.


astore Node Build Status Dependencies Status

Install

This module has zero dependecies.

This module is compatible with Browsers.

npm install astore --save

Context

When communicating with data services or databases, it is very common to include some form of caching layer in front of it. Unfortunatly, cache hit rates are not always optimal. Some resources run very hot and could even be requested multiple times concurrently.

This module is a light wrapper for your data-access object. Provided it's methods accept a single option parameter and return Promises. astore will make sure that no two same requests are made simultaneously.

DAO Example:

function getUser(options) {
  // Make some db call
  return new Promise((resolve, reject) => {
    db.execute('SELECT * from users WHERE id = ?', [options.id], (rows) => {
      if (!rows || !rows.length) return reject();
      resolve(rows[0]);
    });
  });
}

//...

Getting started

You'll need to wrap your dao object and make sure that the signature for calls include an identifier at the top level of the options parameters and in the output.

const astore = require("astore");
const usersDAO = require("../dao/users");
const usersStore = astore(usersDAO, {
  timeoutStep: 1000, // Subsequent requests for the same entity will extend the caching for <timeoutStep> ms.
  maxTimeout: 10000, // This is the maximum caching period for a given entity in ms.
  identifier: "id",   // If the identifier portion of your entity is not labeled "id", you can define it here.
  storageKey: (id, opts) => `${opts.category}.${id}` // The method for assigning unique keys for store entries.
});

/**
 * Get a single entity
 * The first argument represents the arguments that you would normally pass to your DAO.
 * The second is the DOA method to call. Make sure that the reply from the DAO is a single cacheable entity.
 */
usersStore.get({ id: 123 }, "getUser")
  .then((user) => /* The user */);
  
/**
 * Get a list of entities
 * This leverages pre-flight store optimizations by running the actual DAO calls individually.
 * Otherwise, you could use the post-call caching provided with the `search` function.
 */
userStore.getList({ ids: [123, 456, 789] }, "getUser")
  .then((users) => /* The list of users */);
  
userStore.search({ ids: [123, 456, 789] }, "getList")
  .then((users) => /* The list of users */);

/**
 * Skip store features
 * For any sensitive or user-specific data, it is NOT recommended to use storing.
 * To bypass the store, you can use the `direct` method.
 */
userStore.list({ ids: [123, 456, 789] }, "getUser")
  .then((users) => /* The list of users */);

The promise handle as well as the response value will be cached for some time. This is configurable via the timeoutStep value. If other queries are made for that specific identifier, the caching period is extended by the timeoutStep, up to maxTimeout.

The search method first makes the call, then caches the individual entities with the same rules as a single get. You can therefore wrap search methods or list methods alike.

Tests

npm test

Contributing

Pull requests are always welcome! Please follow a few guidelines:

Add a unit test or two to cover the proposed changes Do as the Romans do and stick with existing whitespace and formatting conventions (i.e., spaces instead of tabs, etc) Please note that all interactions with Shutterstock follow the Contributor Covenant Code of Conduct.

Make sure that you also follow the Contributing Guidelines.

License

MIT (c) 2017 Shutterstock