// readme

High-Availability store Efficient data fetching to prevent thundering herds!

HA-store is a wrapper for your data queries, it features:

  • Smart TLRU cache for โ€˜hotโ€™ information
  • Supports multiple caching levels
  • Request coalescing and batching (solves the Thundering Herd problem)
  • Insightful stats and events
  • Lightweight, configurable, battle-tested

Learn how you can improve your appโ€™s performance, design and resilience here!

Installing

npm install ha-store

Usage

// Create your store
import HAStore, {caches} from 'ha-store';

const itemStore = HAStore({
  resolver: getItems,
  delimiter: ['language'],
  caches: [
    caches.inMemory({
      limit: 1000,  // Maximum number of cached items
      ttl: 60000,   // Time to live: 60 seconds
    }),
  ],
});

// Define your resolver
function getItems(ids, params, contexts) {
  // Ids will be a list of all the unique requested items
  // Params will be the parameters for the request, which must be declared in the `delimiter` config of the store
  // Contexts will be the list ofโ€ฆ