superagent-cache
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -69,3 +69,3 @@ /******************************************************** | ||
if(this.method === 'GET'){ | ||
superagent.cacheService.getKey(key, function (err, response){ | ||
superagent.cacheService.get(key, function (err, response){ | ||
if(!err && response){ | ||
@@ -86,3 +86,3 @@ cb(err, response, key); | ||
if(!isEmpty(response) || curProps.cacheWhenEmpty){ | ||
superagent.cacheService.setKey(key, response, curProps.expiration, function(){ | ||
superagent.cacheService.set(key, response, curProps.expiration, function(){ | ||
cb(err, response, key); | ||
@@ -106,3 +106,3 @@ }); | ||
if(!err && response){ | ||
superagent.cacheService.deleteKeys(key, function (){ | ||
superagent.cacheService.del(key, function (){ | ||
cb(err, response, key); | ||
@@ -109,0 +109,0 @@ }); |
{ | ||
"name": "superagent-cache", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Superagent with tiered caching provided by cache-service.", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"superagent": "1.1.0", | ||
"cache-service": "0.1.0" | ||
"cache-service": "0.1.3" | ||
}, | ||
@@ -11,0 +11,0 @@ "devDependencies": { |
# superagent-cache | ||
Superagent with built in tiered caching using [cache-service](https://github.com/fs-webdev/cache-service). | ||
Superagent with built-in tiered caching using [cache-service](https://github.com/fs-webdev/cache-service). | ||
## Basic Usage | ||
# Basic Usage | ||
@@ -24,7 +24,7 @@ Require and instantiate superagent-cache as follows: | ||
## Where does superagent-cache store data? | ||
# Where does superagent-cache store data? | ||
superagent-cache depends on [cache-service](https://github.com/fs-webdev/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](https://github.com/fs-webdev/cache-service) for the complete API. See the [More Examples](#more-usage-examples) section for more detailed examples on caching specifics. | ||
## Install | ||
# Install | ||
@@ -35,3 +35,3 @@ ```javascript | ||
## Run Tests | ||
# Run Tests | ||
@@ -42,7 +42,7 @@ ```javascript | ||
## API | ||
# API | ||
#### require('superagent-cache)(superagent [, cacheServiceConfig]) | ||
## require('superagent-cache)(superagent [, cacheServiceConfig]) | ||
###### Arguments | ||
#### Arguments | ||
@@ -52,21 +52,21 @@ * superagent: an instance of superagent | ||
* {cacheService: an instance of cache-service} | ||
* the same object you would pass to cache-service's constructor | ||
* the same object you would pass to cache-service's [constructor](https://github.com/jpodwys/cache-service#constructor) | ||
#### .get() | ||
## .get() | ||
Same as superagent except that superagent's response object will be cached. | ||
#### .put(), .del() | ||
## .put(), .del() | ||
Same as superagent except that the generated cache key will be automatically invalidated when these HTTP verbs are used. | ||
#### .responseProp(prop) | ||
## .responseProp(prop) | ||
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]. | ||
###### Arguments | ||
#### Arguments | ||
* prop: string | ||
###### Example | ||
#### Example | ||
@@ -85,11 +85,11 @@ ```javascript | ||
#### .prune(callback (response)) | ||
## .prune(callback (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. | ||
###### Arguments | ||
#### Arguments | ||
* callback: a function that accepts superagent's response object and returns a truthy value or null | ||
###### Example | ||
#### Example | ||
@@ -112,11 +112,11 @@ ```javascript | ||
#### .pruneParams(params) | ||
## .pruneParams(params) | ||
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 comitted from the cache key. | ||
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. | ||
###### Arguments | ||
#### Arguments | ||
* params: array of strings | ||
###### Example | ||
#### Example | ||
@@ -136,11 +136,11 @@ ```javascript | ||
#### .pruneOptions(options) | ||
## .pruneOptions(options) | ||
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. | ||
###### Arguments | ||
#### Arguments | ||
* options: array of strings | ||
###### Example | ||
#### Example | ||
@@ -160,39 +160,39 @@ ```javascript | ||
#### .expiration(seconds) | ||
## .expiration(seconds) | ||
Use this function when you need to override all of your caches' defaultExpiration properties for a particular cache entry. | ||
Use this function when you need to override all of your caches' `defaultExpiration` properties (set via cache-service) for a particular cache entry. | ||
###### Arguments | ||
#### Arguments | ||
* seconds: integer | ||
#### .cacheWhenEmpty(bool) | ||
## .cacheWhenEmpty(bool) | ||
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. | ||
###### Arguments | ||
#### Arguments | ||
* bool: boolean, default: true | ||
#### .doQuery(bool) | ||
## .doQuery(bool) | ||
Tell superagent-cache whether to perform an ajax call if the generated cache key is not found. By default, cacheWhenEmpty is true. | ||
###### Arguments | ||
#### Arguments | ||
* bool: boolean, default: true | ||
#### ._end(callback (err, response)) | ||
## ._end(callback (err, response)) | ||
This is a convenience method that allows you to skip all caching logic and use superagent as normal. | ||
###### Arguments | ||
#### Arguments | ||
* callback: a function that accepts superagent's error and response objects | ||
#### .cacheService | ||
## .cacheService | ||
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. | ||
###### Example | ||
#### Example | ||
@@ -203,4 +203,12 @@ ```javascript | ||
## More Usage Examples | ||
# More Usage Examples | ||
Coming soon. | ||
# Roadmap | ||
* Make it so superagent-cache's `.end()` callback function does not require an `err` param | ||
* Make sure that `resetProps()` gets called when `._end()` is called directly | ||
* Add unit tests for the various ways headers can be added to calls | ||
* Add unit tests for the other points above | ||
* Add the 'More Usage Examples' section |
@@ -68,3 +68,3 @@ var expect = require('expect'); | ||
beforeEach(function(){ | ||
superagent.cacheService.flushKeys(); | ||
superagent.cacheService.flush(); | ||
}); | ||
@@ -105,7 +105,7 @@ | ||
expect(response.body.key).toBe('one'); | ||
superagent.cacheService.getKey(key, function (err, result){ | ||
superagent.cacheService.get(key, function (err, result){ | ||
expect(result.body.key).toBe('one'); | ||
}); | ||
setTimeout(function(){ | ||
superagent.cacheService.getKey(key, function (err, result){ | ||
superagent.cacheService.get(key, function (err, result){ | ||
expect(result).toBe(null); | ||
@@ -128,3 +128,3 @@ done(); | ||
expect(response).toBe(false); | ||
superagent.cacheService.getKey(key, function (err, response){ | ||
superagent.cacheService.get(key, function (err, response){ | ||
expect(response).toBe(false); | ||
@@ -147,3 +147,3 @@ done(); | ||
expect(response).toBe(false); | ||
superagent.cacheService.getKey(key, function (err, response){ | ||
superagent.cacheService.get(key, function (err, response){ | ||
expect(response).toBe(null); | ||
@@ -232,3 +232,3 @@ done(); | ||
expect(response.body.key).toBe('one'); | ||
superagent.cacheService.getKey(key, function (err, response){ | ||
superagent.cacheService.get(key, function (err, response){ | ||
expect(response.body.key).toBe('one'); | ||
@@ -246,3 +246,3 @@ done(); | ||
expect(response.body.key).toBe('one'); | ||
superagent.cacheService.getKey(key, function (err, response){ | ||
superagent.cacheService.get(key, function (err, response){ | ||
expect(response.body.key).toBe('one'); | ||
@@ -254,3 +254,3 @@ superagent | ||
expect(response.body.key).toBe('put'); | ||
superagent.cacheService.getKey(key, function (err, response){ | ||
superagent.cacheService.get(key, function (err, response){ | ||
expect(response).toBe(null); | ||
@@ -271,3 +271,3 @@ done(); | ||
expect(response.body.key).toBe('one'); | ||
superagent.cacheService.getKey(key, function (err, response){ | ||
superagent.cacheService.get(key, function (err, response){ | ||
expect(response.body.key).toBe('one'); | ||
@@ -279,3 +279,3 @@ superagent | ||
expect(response.body.key).toBe('put'); | ||
superagent.cacheService.getKey(key, function (err, response){ | ||
superagent.cacheService.get(key, function (err, response){ | ||
expect(response).toBe(null); | ||
@@ -282,0 +282,0 @@ done(); |
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
22151
206
+ Addedcache-service@0.1.3(transitive)
- Removedcache-service@0.1.0(transitive)
Updatedcache-service@0.1.3