Comparing version 3.1.3 to 4.0.0
{ | ||
"name": "cachios", | ||
"version": "3.1.3", | ||
"version": "4.0.0", | ||
"description": "Simple axios cache wrapper using node-cache", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -295,4 +295,22 @@ # Cachios | ||
### Custom object-hash Replacer | ||
By default, Cachios uses an internal `defaultReplacer` function to add FormData support to [object-hash](https://github.com/puleos/object-hash). | ||
To override this, set the `getReplaced` property of your Cachios instance: | ||
```js | ||
const cachios = require('cachios'); | ||
cachios.getReplaced = function (thing) { | ||
if (thing === 'foo') { | ||
return 'bar'; | ||
} | ||
return thing; | ||
}; | ||
``` | ||
## License | ||
[MIT](LICENSE.md) |
@@ -21,2 +21,19 @@ var hash = require('object-hash'); | ||
function defaultReplacer(thing) { | ||
// object-hash doesn't handle FormData values, do it ourselves | ||
// https://github.com/AlbinoDrought/cachios/issues/7 | ||
if (typeof FormData !== 'undefined' && thing instanceof FormData) { | ||
var formDataValues = {}; | ||
var entriesIterator = thing.entries(); | ||
for (var entry = entriesIterator.next(); !entry.done || typeof entry.value !== 'undefined'; entry = entriesIterator.next()) { | ||
formDataValues[entry.value[0]] = defaultReplacer(entry.value[1]); | ||
} | ||
return formDataValues; | ||
} | ||
// object-hash also doesn't support blobs, but I don't think we can read those synchronously | ||
return thing; | ||
} | ||
function Cachios(axiosInstance, nodeCacheConf) { | ||
@@ -33,6 +50,9 @@ this.axiosInstance = axiosInstance; | ||
this.getResponseCopy = defaultResponseCopier; | ||
this.getReplaced = defaultReplacer; | ||
} | ||
Cachios.prototype.getCacheKey = function (config) { | ||
return hash(this.getCacheIdentifier(config)); | ||
return hash(this.getCacheIdentifier(config), { | ||
replacer: this.getReplaced, | ||
}); | ||
}; | ||
@@ -39,0 +59,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44591
29
862
316