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

sf-filecache

v1.0.3

Published

Simple and smart FS based cache system.

Downloads

232

Readme

sf-filecache

Simple and smart FS based cache system.

NPM version Build status Dependency Status devDependency Status Coverage Status Code Climate

sf-filecache exists for two purposes:

  • having a streameable fs based cache system
  • opening only one file descriptor for cache queries

Usage

Buffer based:

var FileCache = require('sf-filecache');

var filecache = new FileCache();

var endOfLife = Date.now() + 36000;

// Set a value in the filecache for the 'plop' key
fileCache.set('plop', new Buffer('plop!'), endOfLife, function(err) {
  if(err) {
    throw err;
  }
  // Retrieve it
  fileCache.get('plop', function(err, data) {
    if(err) {
      return done(err);
    }
    console.log(data.toString()); // plop!
    done();
  });

});

Stream based:

var FileCache = require('sf-filecache');

var filecache = new FileCache();

var endOfLife = Date.now() + 36000;

// Set a stream content in the filecache for the 'plop' key
fileCache.setStream('plop', fs.createReadStream('file'), endOfLife, function(err) {
  if(err) {
    throw err;
  }
  // Retrieve it
  fileCache.getStream('plop', function(err, stream) {
    if(err) {
      return done(err);
    }
    stream.pipe(process.stdout); // plop!
    done();
  });

});

API

FileCache(options)

FileCache constructor

Kind: global function
Api: public

| Param | Type | Description | | --- | --- | --- | | options | Object | Options of the cache (dir, domain and clock) |

fileCache._keyToPath(key) ⇒ String

Transform a key into a path were to save/read the contents

Kind: instance method of FileCache
Returns: String - The computed path
Api: private

| Param | Type | Description | | --- | --- | --- | | key | String | The key to transform |

fileCache._createHeader(header) ⇒ Buffer

Create a bucket header

Kind: instance method of FileCache
Returns: Buffer - The header contents as a buffer
Api: private

| Param | Type | Description | | --- | --- | --- | | header | Object | Header description |

fileCache._readHeader(data) ⇒ Object

Read the header description from a buffer

Kind: instance method of FileCache
Returns: Object - The header description

| Param | Type | Description | | --- | --- | --- | | data | Buffer | The buffer |

fileCache.get(key, cb) ⇒ void

Get cached data for the given key

Kind: instance method of FileCache

| Param | Type | Description | | --- | --- | --- | | key | String | The key | | cb | function | The callback ( signature function(err:Error, data:Buffer) {}) |

fileCache.getStream(key, cb) ⇒ void

Get cached data as a stream for the given key

Kind: instance method of FileCache

| Param | Type | Description | | --- | --- | --- | | key | String | The key | | cb | function | The callback ( signature function(err:Error, stream:ReadableStream) {}) |

fileCache.set(key, data, eol, cb) ⇒ void

Set cached data at the given key

Kind: instance method of FileCache

| Param | Type | Description | | --- | --- | --- | | key | String | The key | | data | Buffer | The data to store | | eol | Number | The resource invalidity timestamp | | cb | function | The callback ( signature function(err:Error) {}) |

fileCache.setStream(key, stream, eol, cb) ⇒ void

Set cached data via a stream at the given key

Kind: instance method of FileCache

| Param | Type | Description | | --- | --- | --- | | key | String | The key | | stream | ReadableStream | The data to store as a readable stream | | eol | Number | The resource invalidity timestamp | | cb | function | The callback ( signature function(err:Error) {}) |

fileCache.setEOL(key, eol, cb) ⇒ void

Set end of life to the given key

Kind: instance method of FileCache

| Param | Type | Description | | --- | --- | --- | | key | String | The key | | eol | Number | The resource invalidity timestamp | | cb | function | The callback ( signature function(err:Error) {}) |