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

bookshelf-cache-redis

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bookshelf-cache-redis - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

2

package.json
{
"name": "bookshelf-cache-redis",
"version": "1.1.0",
"version": "1.2.0",
"description": "A robust, performance-focused caching solution for Bookshelf based on top of Redis.",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -29,3 +29,2 @@ /**

module.exports = (bookshelf, settings) => {
/**

@@ -68,5 +67,12 @@ * @method Model#retrieveCache

// Generic function to override default fetch methods.
async function retrieveCache (options, method) {
const serial = options.hasOwnProperty('serial') ? options.serial : undefined;
async function retrieveCache(options, method) {
const serial = options.hasOwnProperty('serial')
? options.serial
: undefined;
const expired = options.hasOwnProperty('expired')
? options.expired
: 60 * 60; // Default expiration time to 1 hour.
delete options.serial;
delete options.expired;

@@ -77,20 +83,18 @@ if (!serial || disabled === true) {

return redis.get(serial)
.then(async result => {
if (result === null) {
const cache = await this[method](options)
.then(data => data.toJSON());
return redis.get(serial).then(async result => {
if (result === null) {
const cache = await this[method](options).then(data => data.toJSON());
// Store record
redis.set(serial, JSON.stringify(cache));
// Store record
redis.set(serial, JSON.stringify(cache), 'ex', expired);
return ({
toJSON: () => cache
});
}
return {
toJSON: () => cache
};
}
return ({
toJSON: () => JSON.parse(result)
});
});
return {
toJSON: () => JSON.parse(result)
};
});
}

@@ -110,41 +114,37 @@

bookshelf.Model.prototype.fetchAllCache = function (options) {
bookshelf.Model.prototype.fetchAllCache = function(options) {
return retrieveCache.apply(this, [options, 'fetchAll']);
}
};
bookshelf.Model.fetchAllCache = function (...args) {
bookshelf.Model.fetchAllCache = function(...args) {
return this.forge().retrieveCache(...args, 'fetchAll');
}
};
bookshelf.Collection.prototype.fetchAllCache = function (...args) {
bookshelf.Collection.prototype.fetchAllCache = function(...args) {
return fetchAllCache.apply(this.model.forge(), ...args);
};
bookshelf.Model.prototype.fetchPageCache = function (options) {
bookshelf.Model.prototype.fetchPageCache = function(options) {
return retrieveCache.apply(this, [options, 'fetchPage']);
}
};
bookshelf.Model.fetchPageCache = function (...args) {
bookshelf.Model.fetchPageCache = function(...args) {
return this.forge().retrieveCache(...args, 'fetchPage');
}
};
bookshelf.Collection.prototype.fetchPageCache = function (...args) {
bookshelf.Collection.prototype.fetchPageCache = function(...args) {
return retrieveCache.apply(this.model.forge(), ...args);
};
bookshelf.Model.prototype.fetchCache = function (options) {
bookshelf.Model.prototype.fetchCache = function(options) {
return retrieveCache.apply(this, [options, 'fetch']);
}
};
bookshelf.Model.fetchCache = function (...args) {
bookshelf.Model.fetchCache = function(...args) {
return this.forge().retrieveCache(...args, 'fetch');
}
};
bookshelf.Collection.prototype.fetchCache = function (...args) {
bookshelf.Collection.prototype.fetchCache = function(...args) {
return fetchCache.apply(this.model.forge(), ...args);
};
};
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