stores

Fast, reliable and smart caching system heavily based on streams.

stores



Made with obelisk.js.

stores is a fast, reliable, smart caching system heavily based on streams.

stores deals transparently with cache stampede or cache miss storm for you. Basically, it ensures that only one request fetches the resource to be cached. Other ones are put in a queue and served ASAP, when the resource has been fetched or cached.

stores aims to be a solid caching facility that allows you to easily implement your custom backing store. That said, it comes with a balanced filesystem store and an express middleware.

npm install stores --save --production

You're in hurry, I can understand that.
Here is an example on how you can cache processed images easily:

app.get(/\.(?:jpg|png|gif)$/, stores('file', function(reqslotnext) {
    processImage(req).stream().pipe(slot);
});

This ensures that you only process a given image once, and serve the cached version to all others.
It implicitly use the FileStore to cache the image to the filesystem.
slot is a stream pointing to a cache bucket that the FileStore has automatically created.

(Rest of the doc incoming!)

To implement a custom store, you have to inherit from the Store object.

This object provides two methods, _get and _lock that are respectively needed to fetch the resource from the cache or to lock a new cache bucket. A cache bucket can be seen as the physical place where your cached resource will be stored. It can be a file, a memory chunk, a REDIS key, a S3 bucket, or whatever you want.

Nicolas Gryman