Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

superagent-cache

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

superagent-cache - npm Package Compare versions

Comparing version 1.4.1 to 1.5.0

2

package.json
{
"name": "superagent-cache",
"version": "1.4.1",
"version": "1.5.0",
"description": "Superagent with flexible built-in caching.",

@@ -5,0 +5,0 @@ "main": "superagentCache.js",

@@ -7,2 +7,20 @@ # superagent-cache

# Contents
* [Basic Usage](#basic-usage)
* [Install](#install)
* [Run Tests](#run-tests)
* [How Does it Work?](#how-does-it-work)
* [What Exactly Gets Cached?](#what-exactly-gets-cached)
* [Where Does superagent-cache Store Data?](#where-does-superagent-cache-store-data)
* [What Does the Default Configuration Give Me?](#what-does-the-default-configuration-give-me)
* [How Do I Use a Custom Configuration?](#how-do-i-use-a-custom-configuration)
* [Available Configuration Options](#available-configuration-options)
* [Supported Caches](#supported-caches)
* [API](#api)
* [Using Background Refresh](#using-background-refresh)
* [More Usage Examples](#more-usage-examples)
* [Breaking Change History](#breaking-change-history)
* [Release Notes](https://github.com/jpodwys/superagent-cache/releases)
# Basic Usage

@@ -150,2 +168,20 @@

## .then(resolve, reject)
In its [`1.3.0` release](https://github.com/visionmedia/superagent/releases/tag/v1.3.0), superagent added fake promise support in the form of a `.then()` chainable that accepts two functions. Before superagent `2.x`, this function does not return a real promise. Rather, it calls `.end()` internally and then decides which function (`resolve` or `reject`) to call. (superagent-cache does not yet support superagent `2.x`.)
I've overwritten superagent's `.then()` so that the provided `resolve` function accepts the generate cache key as follows:
```javascript
superagent
.get(uri)
.then(function (response, key){
// handle response--key is available if desired
}, function (err){
// handle the error
}
);
```
## .end(callback ([err,] response [, key]))

@@ -169,3 +205,3 @@

//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
//but all other top-level response properties, such as response.ok and response.status, will be ommitted
superagent

@@ -184,3 +220,3 @@ .get(uri)

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. The benefit of using this function is that you can cache only what you need.
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`. The benefit of using this function is that you can cache only what you need.

@@ -198,3 +234,3 @@ #### Arguments

//response will now be replaced with r.body.urer or null
//response will now be replaced with r.body.user or null
//and only r.body.user will be cached rather than the entire superagent response

@@ -235,3 +271,3 @@ superagent

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.
This function works just like the `.pruneParams()` funciton except that it modifies the arguments passed to the `.set()` chainable method (headers) rather than those passed to the `.query()` chainable method.

@@ -333,7 +369,7 @@ #### Arguments

By default, background refresh is off. It will turn itself on the first time you use the `.backgroundRefresh)` chainable.
By default, background refresh is off. It will turn itself on the first time you use the `.backgroundRefresh()` chainable.
#### Setup
`superagent-cache` relies on the background refresh feature of the `cache` param you pass into the `require` command. When you use the `.backgroundRefresh()` chainable, `superagent-cache` passes the provided value into `cache`. This means that if you're using `cache-service`, you almost certainly want `cache-service`'s `writeToVolatileCaches` property set to `true` (it defaults to `true`) so that the data set by background refresh will propogate forward to earlier caches (`cache-service` ONLY background refreshses to the final cache passed to it)
`superagent-cache` relies on the background refresh feature of the `cache` param you pass into the `require` command. When you use the `.backgroundRefresh()` chainable, `superagent-cache` passes the provided value into `cache`. This means that if you're using `cache-service`, you almost certainly want `cache-service`'s `writeToVolatileCaches` property set to `true` (it defaults to `true`) so that the data set by background refresh will propogate forward to earlier caches (`cache-service` ONLY background refreshses the final cache passed to it).

@@ -454,3 +490,3 @@ #### Configure

//...it will return a patched superagent instance and consume cache as its cacheModuleConfig for use with the bundled instance of cacheModule
var cacheModuleConfig = {storage: 'session', defaultExpiraiton: 60};
var cacheModuleConfig = {storage: 'session', defaultExpiration: 60};
var superagent = require('superagent-cache')(null, cacheModuleConfig);

@@ -457,0 +493,0 @@ ```

@@ -79,3 +79,3 @@ var utils = require('./utils');

* Whether to cache superagent's http response object when it "empty"--especially useful with .prune and .pruneParams
* @param {string} responseProp
* @param {boolean} cacheWhenEmpty
*/

@@ -89,3 +89,3 @@ Request.prototype.cacheWhenEmpty = function(cacheWhenEmpty){

* Whether to execute an http query regardless of whether the cache has the generated key
* @param {string} responseProp
* @param {boolean} forceUpdate
*/

@@ -107,2 +107,11 @@ Request.prototype.forceUpdate = function(forceUpdate){

/**
* Overwrites superagent's fake promise support and adds the generated cache key
*/
Request.prototype.then = function(fulfill, reject){
return this.end(function (err, response, key) {
err ? reject(err) : fulfill(response, key);
});
}
/**
* An alias for the .end function because I use ._end and .end for other things

@@ -109,0 +118,0 @@ */

@@ -146,3 +146,3 @@ module.exports = {

/**
* Return a cloneof an object
* Return a clone of an object
* @param {object} obj

@@ -161,3 +161,3 @@ */

/**
* Reset superagent-cache's default query properties using the options defaults object
* Reset superagent-cache's default query properties using the defaults object
* @param {object} d

@@ -164,0 +164,0 @@ */

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc