Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
request-cached-promise
Advanced tools
Readme
Cache proxy class for request-promise: essentially a combination of request-promise and cache-manager with some hashing logic. See:
Note: request-promise uses Bluebird for promises, so you get not a ES6 native Promise but a Bluebird one. This should be a little concern, since Bluebird is Promises/A+ complient.
You can bind the lib to a cache-manager cache and then use, as it were request-promise with all its features.
const rcp = require("request-cached-promise");
const request = rcp.bindToCache(someCache);
request(/* ... */ )
.then (/* ... */)
.catch(/* ... */);
You can bind multiple times to have different caches used for different requests.
const requestMem = rcp.bindToCache(memoryCache);
const requestMultilayer = rcp.bindToCache(multilayerCache);
requestMem(/*...*/).then(/*...*/);
requestMultilayer(/*...*/).then(/*...*/);
... with a simple memory cache, though in real live you might want to use also redis or mongo etc.
const
cacheManager = require("cache-manager"),
cache = cacheManager.caching({
store: 'memory',
max: 100,
ttl: 10 // seconds
}),
request = require("request-cached-promise").bindToCache(cache);
function getUserProfile(userId) {
return request({
uri: "http://some.service/providing/user/" + userId,
json: true
});
}
getUserProfile("john.doe").then(data => {
console.log(data);
// ... and other important stuff
});
The library takes request first parameter and generates a key out of it. If the param is a string, then the key is the URI itself. Otherwise the key is URI with a hash added at the end. This schema is used for easier debugging of cached responses when they're saved in say mongo.
The example above could produce the following record when using cache-manager-mongoose store:
{
"_id" : "http://some.service/providing/user/john.doe _978826362",
"exp" : ISODate("2016-04-17T11:34:32.853Z"),
"val" : {
"id": "john.doe",
"firstName" : "John",
"lastName": "Doe"
}
}
Here _978826362
is a hash generated from the request param:
{
"uri": "http://some.service/providing/user/john.doe",
"json": true
}
The module exports two functions, which you can override if you want.
Override examples:
const rcp = require("request-cached-promise");
rcp.hash = function(str) {
/* my implementation of hashig, e.g. MD5 */
};
rcp.getKey = function(requestParam) {
// in my case all requests have unique URI
// i don't want to hash request params
return requestParam.uri || requestParam;
};
FAQs
promisified http request with caching
The npm package request-cached-promise receives a total of 0 weekly downloads. As such, request-cached-promise popularity was classified as not popular.
We found that request-cached-promise demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.