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

cachios

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cachios - npm Package Compare versions

Comparing version 2.2.4 to 2.2.5

.github/workflows/node.js.yml

22

CHANGELOG.md

@@ -0,1 +1,21 @@

# 2.2.4
Support Axios ^0.21.0 and ^0.20.0 in addition to ^0.18.0 and ^0.19.0
# 2.2.3
Support node-cache ^5.0.0 in addition to ^4.1.1
# 2.2.2
Bump object-hash to ^2.0.0
# 2.2.1
Support Axios ^0.19.0 in addition to ^0.18.0
# 2.2.0
Forced cache invalidation added: https://github.com/AlbinoDrought/cachios/commit/d2612ac3052e420644db75ad18b6f29ea326f589
# 2.1.0

@@ -15,1 +35,3 @@

- `babel-runtime` - this could affect browser compatibility, but it "shouldn't". [Axios already requires promises to be natively supported (it does not polyfill them) and that is the only "new JS" we use](https://github.com/axios/axios#promises).
https://github.com/AlbinoDrought/cachios/pull/43

7

package.json
{
"name": "cachios",
"version": "2.2.4",
"version": "2.2.5",
"description": "Simple axios cache wrapper using node-cache",

@@ -16,3 +16,4 @@ "main": "src/index.js",

],
"coverageDirectory": "tests/coverage"
"coverageDirectory": "tests/coverage",
"testEnvironment": "node"
},

@@ -41,5 +42,5 @@ "repository": {

"express": "^4.16.2",
"jest": "^24.7.1",
"jest": "^26.6.3",
"moxios": "^0.4.0"
}
}
# Cachios
[![Greenkeeper badge](https://badges.greenkeeper.io/AlbinoDrought/cachios.svg)](https://greenkeeper.io/)
[![Dependency Status](https://david-dm.org/albinodrought/cachios.svg)](https://david-dm.org/albinodrought/cachios)
[![npm version](https://badge.fury.io/js/cachios.svg)](https://badge.fury.io/js/cachios)
[![Build Status](https://travis-ci.org/AlbinoDrought/cachios.svg?branch=master)](https://travis-ci.org/AlbinoDrought/cachios)
![Build Status: Node.js CI](https://github.com/AlbinoDrought/cachios/workflows/Node.js%20CI/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/AlbinoDrought/cachios/badge.svg?branch=master)](https://coveralls.io/github/AlbinoDrought/cachios?branch=master)

@@ -8,0 +7,0 @@

@@ -49,2 +49,3 @@ var hash = require('object-hash');

var force = config.force || false;
var cacheablePromise = !config.cancelToken; // refuse to cache cancellable requests until their promise has resolved
var cacheKey = this.getCacheKey(config);

@@ -60,3 +61,3 @@ var cachedValue = this.getCachedValue(cacheKey);

// return it.
if (this.stagingPromises[cacheKey]) {
if (cacheablePromise && this.stagingPromises[cacheKey]) {
return this.stagingPromises[cacheKey];

@@ -73,5 +74,7 @@ }

// - our cache backend may not support promises
this.stagingPromises[cacheKey] = pendingPromise;
if (cacheablePromise) {
this.stagingPromises[cacheKey] = pendingPromise;
}
// once the request successfully copmletes, store it in cache
// once the request successfully completes, store it in cache
pendingPromise.then(function (resp) {

@@ -78,0 +81,0 @@ me.setCachedValue(cacheKey, me.getResponseCopy(resp), ttl);

@@ -15,3 +15,3 @@ const cachios = require('./../src');

test('nothing should explode if a request is cancelled', (done) => {
test('nothing should explode if a request is cancelled', async () => {
jest.useFakeTimers();

@@ -23,25 +23,35 @@

const CancelToken = axios.CancelToken;
const source = CancelToken.source();
let source = CancelToken.source();
cachiosInstance.get(url, {
const cachiosPromise = cachiosInstance.get(url, {
cancelToken: source.token,
}).then((resp) => {
});
source.cancel('test');
try {
await cachiosPromise;
// this should never happen!
expect(false).toBe(true);
done();
}).catch((ex) => {
throw new Error('Promise should not successfully resolve, we cancelled it!');
} catch (ex) {
// we should receive the normal axios cancel exception here
// (and no "null" issues)
expect(ex.message).toBe('test');
done();
}
source = CancelToken.source();
moxios.stubRequest(url, {
status: 200,
});
setTimeout(() => {
source.cancel('test');
}, 10);
jest.runOnlyPendingTimers();
// intentionally never resolve moxios request
// we want to cancel the request before it finishes.
try {
const resp = await cachiosInstance.get(url, {
cancelToken: source.token,
});
expect(resp.status).toBe(200);
} catch (ex) {
throw new Error(`The cancelled request was unexpectedly cached, reproducing https://github.com/AlbinoDrought/cachios/issues/55`);
}
});
});

@@ -25,14 +25,8 @@ const globalCachios = require('./../src');

});
cachios = globalCachios.create(globalAxios);
socket = server.listen(PORT, done);
cachios = globalCachios.create(globalAxios);
});
afterEach((done) => {
if (!server || !socket) {
return done();
}
socket.close(done);
server = undefined;
socket = undefined;
});

@@ -68,22 +62,18 @@

// hit our test url and check if we hit it or if it was returned from cache
const hitAndCheck = (hitCounter, cachiosInstance, expectedHits) => {
const hitAndCheck = async (hitCounter, cachiosInstance, expectedHits) => {
const url = hitCounter.url();
return Promise.resolve()
.then(() => cachiosInstance[hitCounter.method](url))
.then((resp) => {
// make sure we receive the expected text
expect(resp.data).toBe(hitCounter.body);
// make sure our hit counter matches up with our expected amount of hits
expect(hitCounter.hits).toBe(expectedHits);
});
const resp = await cachiosInstance[hitCounter.method](url);
// make sure we receive the expected text
expect(resp.data).toBe(hitCounter.body);
// make sure our hit counter matches up with our expected amount of hits
expect(hitCounter.hits).toBe(expectedHits);
};
methods.forEach((method) => {
test(`should work in a somewhat-real environment: ${method}`, () => {
test(`should work in a somewhat-real environment: ${method}`, async () => {
const hitCounter = makeHitCounter(server, method, BASE);
let promise = Promise.resolve();
for (let i = 0; i < HITS_TO_PERFORM; i += 1) {
promise = promise.then(() => hitAndCheck(hitCounter, cachios, 1));
await hitAndCheck(hitCounter, cachios, 1);
}

@@ -93,44 +83,32 @@

// (ensures hit counter at least works a little)
promise = promise
.then(() => cachios.cache.flushAll())
.then(() => hitAndCheck(hitCounter, cachios, 2));
return promise;
await cachios.cache.flushAll();
await hitAndCheck(hitCounter, cachios, 2);
});
test(`should bypass cache when \`force\` is set: ${method}`, () => {
test(`should bypass cache when \`force\` is set: ${method}`, async () => {
const hitCounter = makeHitCounter(server, method, BASE);
let promise = Promise.resolve();
for (let i = 0; i < HITS_TO_PERFORM; i += 1) {
promise = promise
.then(() => cachios.request({
await cachios.request({
method: method,
url: hitCounter.url(),
})).then(() => {
expect(hitCounter.hits).toBe(1);
});
expect(hitCounter.hits).toBe(1);
}
// set force = true to bypass cache
promise = promise
.then(() => cachios.request({
await cachios.request({
method: method,
url: hitCounter.url(),
force: true,
})).then(() => {
expect(hitCounter.hits).toBe(2);
});
})
expect(hitCounter.hits).toBe(2);
// unforced request after forced request should still receive cached response
promise = promise
.then(() => cachios.request({
await cachios.request({
method: method,
url: hitCounter.url(),
})).then(() => {
expect(hitCounter.hits).toBe(2);
});
return promise;
})
expect(hitCounter.hits).toBe(2);
});

@@ -145,7 +123,5 @@

*/
test(`should work when sending simultaneous requests: ${method}`, () => {
test(`should work when sending simultaneous requests: ${method}`, async () => {
const hitCounter = makeHitCounter(server, method, BASE);
let promise = Promise.resolve();
for (let i = 0; i < HITS_TO_PERFORM; i += 1) {

@@ -157,3 +133,3 @@ // send simultaneous hits

}
promise = promise.then(() => Promise.all(hits));
await Promise.all(hits);
}

@@ -163,9 +139,6 @@

// (ensures hit counter at least works a little)
promise = promise
.then(() => cachios.cache.flushAll())
.then(() => hitAndCheck(hitCounter, cachios, 2));
return promise;
await cachios.cache.flushAll();
await hitAndCheck(hitCounter, cachios, 2);
});
});
});
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