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

nce-cache

v0.0.1

Published

An extension to cache content in nce

Downloads

4

Readme

Caching extension for NCE

Description

This is an extension for the nce framework for caching content.

How to install

Install with npm: npm install --save nce-cache

Integrate in NCE with the extension-manager:

var NCE = require("nce");
var nce = new NCE(/*{}*/);
var extMgr = require("nce-extension-manager")(nce);
extMgr.activateExtension(extMgr);

var cache = extMgr.getActivatedExtension("cache");

How to use

This caching extension is able to cache multiple resources on one requested url. The extension distinguishes content by the following header fields:

  • Accept / Content-Type
  • Accept-Charset / Content-Type
  • Accept-Language / Content-Type

and delivers (if available) the best content (or just call next() to give other extensions the chance to deliver the content).

You are able to use this extension in combination with nce-user to provide also cached resources only for authenticated users and you are able to provide cached-content only for specific users.

You are able to uncache resources, or set an expire-header as ttl.

Config settings

You are able to use the following config-settings (listed with their defaults):

  • dumpPath: process.cwd() + "/cache-data": Directory to dump files.

  • fallbackContentType: "text/html": The fallback content type if resource has none.

  • fallbackLanguage: "en": The fallback language if resource has none (if you have nce-i18n installed this extension take its fallback-language).

  • fallbackCharset: "utf-8": The fallback charset if resource has none.

  • fallbackCacheControlValue: "max-age=3600": The fallback value for cache-control header.

  • allowUsers: false: Proof for valid user with nce-user (use like described the options in this section).

  • disableAutoETag: false: Set to true if you don't want to create a ETag for a resource automatically if it has none.

  • disableAutoLastModified: false: Set to true if you don't want to create a last-modified-header for a resource automatically if it has none.

  • disableAutoContentLength: false: Set to true if you don't want to create a header for the content-length of a resource automatically if it has none.

  • disableAutoCacheControl: false: Set to true if you don't want to create a cache-control-header for a resource automatically if it has none.

  • sloppyErrorHandling: false: Set to true if you want to call next() on every error thrown by this extension.

  • logger: {}: Settings for logger-extension

Basic methods

ext.uncache(url, cb)

Uncache a resource by url.

Arguments
  1. url[String]: The url as identifier.
  2. cb[Function]: Callback-function from node module rmdir with the arguments:
    1. error[Error]: Used for exceptions.
    2. dir[Array]: List of deleted directories.
    3. files[Array]: List of deleted files.

ext.cacheContent(url, headers, content, cb, opts)

Cache a content directly, without a stream.

Arguments
  1. url[String]: The url as identifier.
  2. headers[Object]: Headers to be send.
  3. content[String or Buffer]: The content to cache.
  4. cb[Function]: Callback-function with the arguments:
    1. error[Error]: Used for exceptions.
  5. opts[Object]: The same options as used with ext.cacheStream(...).

ext.cacheStream(url, headers, cb, opts)

Cache content with a write-stream.

Arguments
  1. url[String]: The url as identifier.
  2. headers[Object]: Headers to be send.
  3. cb[Function]: Callback-function with the arguments:
    1. error[Error]: Used for exceptions.
    2. stream[Stream]: A write stream.
  4. opts[Object]: All options are optional and get set with the config-settings
    • allowUsers[Object or false]: Users, usergroups, emails and ids of users that are allowed to access a cached resource. If you don't want to provide a user-authentication set to false, otherwise use like described for options on this method from nce-user.
    • disableAutoETag[Boolean]: Disable or enable just for this resource.
    • disableAutoLastModified[Boolean]: Disable or enable just for this resource.
    • disableAutoContentLength[Boolean]: Disable or enable just for this resource.
    • disableAutoCacheControl[Boolean]: Disable or enable just for this resource.
    • fallbackContentType[String]: Fallback value for content-type for this resource.
    • fallbackCharset[String]: Fallback value for charset for this resource.
    • fallbackLanguage[String]: Fallback value for language for this resource.
    • fallbackCacheControlValue[String]: Fallback value for cache-control for this resource.
    • supported[Object]: Object of support informations:
      • languages[Array]: List of languages supported on this url.
      • contentTypes[Array]: List of content-types supported on this url.
      • charsets[Array]: List of charsets supported on this url.
    • fallback[Object]: Object of fallback informations. You can set to false if you want to provide every possibility.
      • language[String]: Fallback language.
      • contentType[String]: Fallback content-type.
      • charset[String]: Fallback charset.

ext.getStream(url, headers, cb, user)

Get a cached resource as a stream.

Arguments
  1. url[String]: The url as identifier.
  2. headers[Object]: Headers from client.
  3. cb[Function]: Callback-function with the arguments:
    1. error[Error]: Used for exceptions.
    2. stream[Stream]: A readable stream.
  4. user[Object]: A valid user object from nce-user.