moov_cache is a MoovJS Node module that provides a number of methods to enable caching for your Moovweb-transformed project site.
To instantiate a new moov_cache object in your MoovJS project, you can use the following:
var moov_cache = require("moov_cache"); var cache = new moov_cache(fns, $, env);
In this example, we are using
env global objects available
in the Node.js VM where your code is executed.
fns refers to
moov_stdlib, used as a source of
$ is an instance of
moov_cheerio, used as the HTML
content selector, and
env is a reference to the set of environment variables
associated with a request as it goes through the Moovweb server.
Enables the caching header for the page.
This function will set the cache header of your page to true with no additional parameters
Enables caching of things for a specified period of time.
This function will set the necessary headers to tell Moovweb to cache the current response. The parameter is the number of seconds to cache things for.
Adds a forced caching header to the page.
This function will set the cache control header to a non-zero TTL. The cache headers will be set regardless of the upstream response's cache headers (even if its set to max-age 0 for example).
Forces caching of things for a specified period of time in Moovweb's cache only.
This function will set the necessary headers to tell Moovweb to cache the current response and strip other caching headers out. The parameter is the number of seconds to cache things for.
This html function sets up the page so that content you label dynamic is fetched as needed, but still allows the static section of the page to be cached.
This will set up the page so that all chosen tag parts(e.g. div) with the "dynamic" attribute are stripped out and will be loaded later. If it is a fragment/dynamic hit, content in the cachebox will be stored into a JSON array and get returned.
Unlike tritium html scope, enc argument will not change the encoding but just export "Content-Type-Charset" to be the enc. If enc is undefined, the encoding flag will set "utf-8" as default.
This function goes hand-in-hand with the cache function to allow dynamic sections to be flagged and loaded later. Use this function to specify dynamic content that should not be cached.
$ cp .npmrc.example .npmrc $ npm install
This will build the Node modules that moov_cache depends under the local moov_cache directory. The npm-shrinkwrap.json file is used to version-lock all dependencies.
$ npm test
Run Locally via Node CLI
$ node --harmony ... > var moov_cache = require("./main.js");