alltherooms / cached-request

Node.js module to perform HTTP requests with caching support
MIT License
61 stars 23 forks source link

Custom Cache Keys #21

Closed ghost closed 7 years ago

ghost commented 7 years ago

Whats about adding an Option for Custom Cache Keys?

 if(options.customkey) {
      key = options.customkey;
  } else {
  key = JSON.stringify(this.normalizeOptions(options));
  key = this.hashKey(key);
  }
elhoyos commented 7 years ago

You can have custom keys by overwriting CachedRequest#hashKey.


const cr = require('cached-request')(request)
cr.hashKey = (stringifiedOptions) => {
  // return a string
}