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

onionskin

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

onionskin - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

2

bower.json
{
"name": "onionskin",
"version": "1.0.0",
"version": "1.1.0",
"authors": [

@@ -5,0 +5,0 @@ "Tadeu Zagallo <tadeuzagallo@gmail.com>"

{
"name": "onionskin",
"version": "1.0.0",
"version": "1.1.0",
"description": "Multilayer Cache Manager for JavaScript",

@@ -38,3 +38,3 @@ "main": "src/onionskin.js",

"dependencies": {
"bluebird": "~1.2.4"
"bluebird": "~2.0.5"
},

@@ -41,0 +41,0 @@ "testling": {

# [![OnionSkin](logo/onionskin.png)](http://onionskin.io) [OnionSkin](http://onionskin.io) #
[![NPM version](https://badge.fury.io/js/onionskin.svg)](http://badge.fury.io/js/onionskin) [![Dependency Status](https://david-dm.org/onionskin/onionskin.svg)](https://david-dm.org/onionskin/onionskin) [![Build Status](https://travis-ci.org/onionskin/onionskin.svg?branch=master)](https://travis-ci.org/onionskin/onionskin) [![Code Climate](https://codeclimate.com/github/onionskin/onionskin.png)](https://codeclimate.com/github/onionskin/onionskin) [![Code Climate](https://codeclimate.com/github/onionskin/onionskin/coverage.png)](https://codeclimate.com/github/onionskin/onionskin)

@@ -30,5 +31,8 @@ OnionSkin is multi-layer cache manager library that works with Node.js and vanilla javascript

pool.get('my/key/path').catch(function (err) {
pool.get('my/key/path', function (err) {
// Data is either inexistent or expired
return slowFuncThatReturnsPromise().then(this.save);
return slowFuncThatReturnsPromise();
}).then(function (value) {
// The value that was either on cache or was just generated
console.log(value);
});

@@ -104,1 +108,7 @@ ```

If you want to join just follow the [instructions](#want-to-help), any help will be very welcome.
## Changelog
### 1.0.1
* The function to generate missing cache should be passed as the last parameter to `pool.get`, although generating cache `Promise.catch` is still supported the cache will never be unlocked if `item.save` or `item.set` are not called.
* Also when the cache generator function is passed as parameter, there is no need to call either `item.save` or `item.set`, just return the value you want to be cached and it will automatically saved and passed along to the promise chain.

@@ -102,4 +102,5 @@ 'use strict';

Item.prototype.save = function (value, expiration) {
this.set(value, expiration);
return value;
return this.set(value, expiration).then(function () {
return value;
});
};

@@ -106,0 +107,0 @@

@@ -29,15 +29,30 @@ var Promise = require('bluebird');

Pool.prototype.get = function (key, cachePolicy, policyData) {
Pool.prototype.get = function (key, cachePolicy, policyData, generator) {
var item = this.getItem(key);
return new Promise(function (resolve, reject) {
item.get(cachePolicy, policyData).then(function (data) {
item.isMiss().then(function (missed) {
if (missed) {
item.lock();
reject('Cache is missing');
} else {
resolve(data);
if (typeof cachePolicy === 'function') {
generator = cachePolicy;
cachePolicy = void 0;
} else if (typeof policyData === 'function') {
generator = policyData;
policyData = void 0;
}
return item.get(cachePolicy, policyData).then(function (data) {
return item.isMiss().then(function (missed) {
if (missed) {
item.lock();
if (!generator) {
throw 'Cache is missing';
}
});
return Promise.try(generator)
.then(function (val) {
return item.save(val);
}).catch(function () {
return item.unlock();
});
} else {
return data;
}
});

@@ -44,0 +59,0 @@ }).bind(item);

@@ -51,6 +51,8 @@ describe('OnionSkin::Pool', function () {

it('should fail if the item isn\'t present', function (done) {
pool.get('non_existing_key').then(function (data) {
done(new Error('It should have failed', data));
}).catch(function () {
done();
pool.get('non_existing_key').catch(function () {
return 10;
}).then(function (data) {
catching(done, function () {
expect(data).to.be.equal(10);
});
});

@@ -60,4 +62,4 @@ });

it('should allow save on fail', function (done) {
pool.get('non_existing_key2').catch(function (err) {
return this.set('bar');
pool.get('non_existing_key2', function (err) {
return 'bar';
}).then(function () {

@@ -74,3 +76,3 @@ return pool.get('non_existing_key2');

var key = 'pool_get_3';
pool.get(key).catch(function (err) {
pool.get(key, function (err) {
pool.getItem(key).isLocked().then(function (locked) {

@@ -84,3 +86,28 @@ catching(done, function () {

it('should automatically unlock the cache after save', function (done) {
pool.get('non_existing_key3', function () {
return 1;
}).then(function (value) {
expect(value).to.be.equal(1);
this.isLocked().then(function (locked) {
catching(done, function () {
expect(locked).to.be.false;
});
});
}).done();
});
it('should automatically unlock the cache if generation fails', function (done) {
pool.get('non_existing_key3', function () {
throw 'Some error!';
}).finally(function () {
this.isLocked().then(function (locked) {
catching(done, function () {
expect(locked).to.be.false;
});
});
}).done();
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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