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

cache-manager-fs-stream

v2.0.2

Published

file system store for node cache manager with binary data as files

Downloads

65

Readme

NPM

cache-manager-fs-stream

Node Cache Manager store for Filesystem with binary data

The Filesystem store for the node-cache-manager module, storing binary data as separate files, returning them as readable streams or buffers. This should be convenient for caching binary data and sending them as streams to a consumer, e.g. res.send(). The library caches on disk arbitrary data, but values of an object under the special key binary is stored as separate files.

Node.js versions

Works with versions upper than 16.x

Installation

    npm install cache-manager-fs-stream --save

Features

  • limit maximum size on disk
  • refill cache on startup (in case of application restart)
  • returns binary data as buffers or readable streams
  • can store buffers inside the single cache file

Single store

// node cachemanager
import { caching } from 'cache-manager';
// storage for the cachemanager
import { DiskStoreCache, create } from 'cache-manager-fs-stream';
// initialize caching on disk
const diskstore = create({
  ttl: 60 * 60 /* seconds */,
  maxsize: 1000 * 1000 * 1000 /* max size in bytes on disk */,
  path: 'diskcache',
  binaryEncode: true, // File will be binary encoded (serialized with v8)
  zip: true, // use zip to compress the cache files
});

const diskCache = await caching(diskstore);

// ...
var cacheKey = 'userImageWatermarked:' + user.id + ':' + image.id;
var ttl = 60 * 60 * 24 * 7 * 1000; // in ms

// wrapper function, see more examples at node-cache-manager
const result = diskCache.wrap(
  cacheKey,
  // called if the cache misses in order to generate the value to cache
  async () => {
    // get the image from the database
    return value; // value can be object, Buffer, Stream
  },
  // Options, see node-cache-manager for more examples
  { ttl: ttl },
);

Options

options for store initialization

// default values

// time to live in seconds
options.ttl = 60;
// path for cached files
options.path = 'cache/';
// prevent filling of the cache with the files from the cache-directory
options.preventfill = false;
// if true the main cache files will be zipped (not the binary ones)
options.zip = false;
// maximum size of the cache in bytes
options.maxsize = 1000 * 1000 * 1000;
// if true, the binary files are encoded with v8
options.binaryEncode = false;

Tests

To run tests:

    npm test

License

cache-manager-fs-stream is licensed under the MIT license.

Credits

Based on https://github.com/sheershoff/node-cache-manager-fs-binary