simple-request-caching
A very simple caching approach for requests.
install
There are no external dependencies for the code, so feel free to copy+paste it into whatever framework you are using (e.g., here's an Angular example). Otherwise, install using:
npm install simple-request-caching
using
The basic setup is this:
var CachedRequest = var request = cacheMillis: 500 // the millis that the request is cached, or -1 for forever { return http }
Set a single one of those up for any request you want to cache, then use it like:
api
When you make a new CachedRequest
, it has the following parameters:
cacheMillis
(required): The number of milliseconds to cache the request response. Use-1
to cache things forever.request
(required): The function called when a request is not cached. Must return a promise. Rejected promises are not cached.stringify
(optional): A function that is called to stringify the request parameters. If unspecified, a default is used which will stringify flat object correctly and efficiently. If you have deeper objects, you'll want to implement your ownstringify
function.