Class: OfflineCache

OfflineCache(name, persistencestore)

Offline Persistence Toolkit implementation of the standard Cache API. In additional to functionalities provided by the standard Cache API, this OfflineCache also interacts with shredding methods for more fine-grain caching.

Constructor

new OfflineCache(name, persistencestore)

Parameters:
Name Type Description
name String name of the cache
persistencestore Object instance for cache storage
Source:

Methods

(static) .upsertAll(requests) → {Promise}

Bulk operation of add.
Parameters:
Name Type Description
requests Array An array of Request
Source:
Returns:
Returns a promise when all the requests in the array are handled.
Type
Promise

##add(request) → {Promise}

Takes a request, retrieves it and adds the resulting response object to the cache.
Parameters:
Name Type Description
request Request The request object to fetch for response and be cached.
Source:
Returns:
returns a Promise that is resolved when the reponse is retrieved and request/response is cached.
Type
Promise

##delete(request, options) → {Promse}

Delete the all the entries in the cache that matches the passed-in request with the specified options.
Parameters:
Name Type Description
request Request The request object to match against
options Object Options to control the matching operation
  • options.ignoreSearch A Boolean that specifies whether to ignore the query string in the url. For example, if set to true the ?value=bar part of http://foo.com/?value=bar would be ignored when performing a match. It defaults to false.
  • options.ignoreMethod A Boolean that, when set to true, prevents matching operations from validating the Request http method (normally only GET and HEAD are allowed.) It defaults to false.
  • options.ignoreVary A Boolean that when set to true tells the matching operation not to perform VARY header matching — i.e. if the URL matches you will get a match regardless of whether the Response object has a VARY header. It defaults to false.
Source:
Returns:
Finds the Cache entry whose key is the request, and if found, deletes the Cache entry and returns a Promise that resolves to true. If no Cache entry is found, it returns a Promise that resolves to false.
Type
Promse

##getName() → {string}

Retrieve the name of the cache object.
Source:
Returns:
Returns the name of the cache object.
Type
string

##hasMatch(request, options) → {Promise}

Checks if a match to this request with the specified options exist in the cache or not. This is an optimization over match because we don't need to query out the shredded data to fill the response body.
Parameters:
Name Type Description
request Request The request object to match against
options Object Options to control the matching operation
  • options.ignoreSearch A Boolean that specifies whether to ignore the query string in the url. For example, if set to true the ?value=bar part of http://foo.com/?value=bar would be ignored when performing a match. It defaults to false.
  • options.ignoreMethod A Boolean that, when set to true, prevents matching operations from validating the Request http method (normally only GET and HEAD are allowed.) It defaults to false.
  • options.ignoreVary A Boolean that when set to true tells the matching operation not to perform VARY header matching — i.e. if the URL matches you will get a match regardless of whether the Response object has a VARY header. It defaults to false.
Source:
Returns:
Returns a promise that resolves to true if a match exist while false otherwise.
Type
Promise

##keys(request, options) → {Promise}

Retrieves all the keys in this cache.
Parameters:
Name Type Description
request Request The request object to match against
options Object Options to control the matching operation
  • options.ignoreSearch A Boolean that specifies whether to ignore the query string in the url. For example, if set to true the ?value=bar part of http://foo.com/?value=bar would be ignored when performing a match. It defaults to false.
  • options.ignoreMethod A Boolean that, when set to true, prevents matching operations from validating the Request http method (normally only GET and HEAD are allowed.) It defaults to false.
  • options.ignoreVary A Boolean that when set to true tells the matching operation not to perform VARY header matching — i.e. if the URL matches you will get a match regardless of whether the Response object has a VARY header. It defaults to false.
Source:
Returns:
Returns a promise that resolves to an array of Cache keys.
Type
Promise

##match(a, options) → {Promise}

Find the first response in this Cache object that match the request with the options.
Parameters:
Name Type Description
a Request request object to match against
options Object Options to control the matching operation
  • options.ignoreSearch A Boolean that specifies whether to ignore the query string in the url. For example, if set to true the ?value=bar part of http://foo.com/?value=bar would be ignored when performing a match. It defaults to false.
  • options.ignoreMethod A Boolean that, when set to true, prevents matching operations from validating the Request http method (normally only GET and HEAD are allowed.) It defaults to false.
  • options.ignoreVary A Boolean that when set to true tells the matching operation not to perform VARY header matching — i.e. if the URL matches you will get a match regardless of whether the Response object has a VARY header. It defaults to false.
Source:
Returns:
Returns a Promise that resolves to the Response associated with the first matching request in the Cache object. If no match is found, the Promise resolves to undefined.
Type
Promise

##matchAll(request, options) → {Promise}

Finds all responses whose request matches the passed-in request with the specified options.
Parameters:
Name Type Description
request Request The request object to match against
options Object Options to control the matching operation
  • options.ignoreSearch A Boolean that specifies whether to ignore the query string in the url. For example, if set to true the ?value=bar part of http://foo.com/?value=bar would be ignored when performing a match. It defaults to false.
  • options.ignoreMethod A Boolean that, when set to true, prevents matching operations from validating the Request http method (normally only GET and HEAD are allowed.) It defaults to false.
  • options.ignoreVary A Boolean that when set to true tells the matching operation not to perform VARY header matching — i.e. if the URL matches you will get a match regardless of whether the Response object has a VARY header. It defaults to false.
Source:
Returns:
Returns a Promise that resolves to an array of response objects whose request matches the passed-in request.
Type
Promise

##put(request, response) → {Promise}

Add the request/response pair into the cache.
Parameters:
Name Type Description
request Request Request object of the pair
response Response Response object of the pair
Source:
Returns:
Returns a promise when the request/response pair is cached.
Type
Promise