Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
superagent-cache
Advanced tools
Superagent with built-in tiered caching using cache-service.
Require and instantiate superagent-cache as follows:
var superagent = require('superagent');
require('superagent-cache')(superagent);
Now you're ready for the magic! All of your existing GET
requests will be cached with no extra bloat in your queries!
superagent
.get(uri)
.end(function (err, response){
// response is now cached!
// subsequent calls to this superagent request will now fetch the cached response
}
);
Enjoy!
superagent-cache depends on cache-service to manage caches and store and retrieve data. cache-service supports any type of cache that has been wrapped in its interface (redis and node-cache wrappers are provided by default). See cache-service's docs for the complete API. See the More Examples section for more detailed examples on caching specifics.
npm install superagent-cache
npm test
Same as superagent except that superagent's response object will be cached.
Same as superagent except that the generated cache key will be automatically invalidated when these HTTP verbs are used.
If you know you want a single, top-level property from superagent's response object, you can optimize what you cache by passing the property's name here. When used, it causes the .end() function's response to return superagent's response[prop].
//response will now be replaced with superagent's response.body
//but all other top-level response properties,such as response.ok and response.status, will be ommitted
superagent
.get(uri)
.responseProp('body')
.end(function (error, response){
// handle response
}
);
If you need to dig several layers into superagent's response, you can do so by passing a function to .prune(). Your prune function will receive superagent's response and should return a truthy value or null.
var prune = funtion(r){
return (r && r.ok && r.body && r.body.user) ? r.body.user : null;
}
//response will now be replaced with r.body.urer or null
//and only r.body.user will be cached rather than the entire superagent response
superagent
.get(uri)
.prune(prune)
.end(function (error, response){
// handle response
}
);
In the event that you need certain query params to execute a query but cannot have those params as part of your cache key (useful when security or time-related params are sent), use .pruneParams() to remove those properties. Pass .pruneParams() an array containing the param keys you want omitted from the cache key.
//the superagent query will be executed with all params
//but the key used to store the superagent response will be generated without the passed param keys
superagent
.get(uri)
.query(query)
.pruneParams(['token'])
.end(function (error, response){
// handle response
}
);
This function works just like the .pruneParams() funciton except that it modifies the arguments passed to the .set() chainable method rather than those passed to the .query() chainable method.
//the superagent query will be executed with all headers
//but the key used to store the superagent response will be generated without the passed header keys
superagent
.get(uri)
.set(options)
.pruneOptions(['token'])
.end(function (error, response){
// handle response
}
);
Use this function when you need to override all of your caches' defaultExpiration
properties (set via cache-service) for a particular cache entry.
Tell superagent-cache whether to cache the response object when it's false
, null
, or {}
.This is especially useful when using .responseProp() or .prune() which can cause response to be falsy. By default, cacheWhenEmpty is true.
Tell superagent-cache whether to perform an ajax call if the generated cache key is not found. By default, cacheWhenEmpty is true.
This is a convenience method that allows you to skip all caching logic and use superagent as normal.
If you don't have an external reference to superagent-cache's underlying cache-service instance, you can always get to it this way in case you need to manually add/invalidate keys you get from sources other than superagent queries.
superagent.cacheService... //See cache-service's documentation for what you can do here
Coming soon.
.end()
callback function does not require an err
paramresetProps()
gets called when ._end()
is called directlyFAQs
Superagent with flexible built-in caching.
The npm package superagent-cache receives a total of 861 weekly downloads. As such, superagent-cache popularity was classified as not popular.
We found that superagent-cache 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.