0.0.8 • Published 9 years ago
sw-cacheable-response-behavior v0.0.8
sw-cacheable-response-behavior
This library takes a Response object and determines whether it's cacheable, based on a specific configuration.
Installation
npm install --save-dev sw-cacheable-response-behavior
Demo
Browse sample source code in the demo directory, or try it out directly.
API
sw-cacheable-response-behavior
packages/sw-cacheable-response-behavior/src/index.js:21-21
sw-cacheable-response-behavior Module
Behavior
packages/sw-cacheable-response-behavior/src/lib/behavior.js:48-119
Examples
// Used as an automatically invoked as "behavior" by a RequestWrapper:
const cacheName = 'runtime-cache';
const requestWrapper = new goog.runtimeCaching.RequestWrapper({
  cacheName,
  behaviors: [
    new goog.cacheableResponse.Behavior({
      statuses: [0, 200, 404]
    })
  ]
});
// Set up a route to match any requests made against the example.com domain.
// The responses will be cached if the response code is 0, 200, or 404, and
// will not be cached otherwise.
const route = new goog.routing.RegExpRoute({
  match: ({url}) => url.domain === 'example.com',
  handler: new goog.runtimeCaching.StaleWhileRevalidate({requestWrapper})
});// Explicitly invoked usage independent of the goog.routing framework, via
// the isResponseCacheable() method:
// TODO: Write sample code.constructor
packages/sw-cacheable-response-behavior/src/lib/behavior.js:62-73
Creates a new Behavior instance, which stores configuration and logic
to determine whether a Response object is cacheable or not.
If multiple criteria are present (e.g. both statuses and headers), then
the Response needs to meet all of the criteria to be cacheable.
Parameters