nce-cache
v0.0.1
Published
An extension to cache content in nce
Downloads
1
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 totrue
if you don't want to create a ETag for a resource automatically if it has none.disableAutoLastModified: false
: Set totrue
if you don't want to create a last-modified-header for a resource automatically if it has none.disableAutoContentLength: false
: Set totrue
if you don't want to create a header for the content-length of a resource automatically if it has none.disableAutoCacheControl: false
: Set totrue
if you don't want to create a cache-control-header for a resource automatically if it has none.sloppyErrorHandling: false
: Set totrue
if you want to callnext()
on every error thrown by this extension.logger: {}
: Settings for logger-extension
Basic methods
ext.uncache(url, cb)
Uncache a resource by url.
Arguments
url
[String]: The url as identifier.cb
[Function]: Callback-function from node module rmdir with the arguments:error
[Error]: Used for exceptions.dir
[Array]: List of deleted directories.files
[Array]: List of deleted files.
ext.cacheContent(url, headers, content, cb, opts)
Cache a content directly, without a stream.
Arguments
url
[String]: The url as identifier.headers
[Object]: Headers to be send.content
[String or Buffer]: The content to cache.cb
[Function]: Callback-function with the arguments:error
[Error]: Used for exceptions.
opts
[Object]: The same options as used with ext.cacheStream(...).
ext.cacheStream(url, headers, cb, opts)
Cache content with a write-stream.
Arguments
url
[String]: The url as identifier.headers
[Object]: Headers to be send.cb
[Function]: Callback-function with the arguments:error
[Error]: Used for exceptions.stream
[Stream]: A write stream.
opts
[Object]: All options are optional and get set with the config-settingsallowUsers
[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 tofalse
, 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 tofalse
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.