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

cacheable

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cacheable - npm Package Compare versions

Comparing version 0.2.0 to 0.2.4

lib/cacheable.js

2

index.js

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

module.exports = require('./lib/cached.js');
module.exports = require('./lib/cacheable.js');

@@ -5,5 +5,5 @@ // Global cache for constructor classes

var Cached = require('./cached')
var Cacheable = require('./cacheable')
var _REALNAME = Cached._REALNAME
var _REALNAME = Cacheable._REALNAME

@@ -13,3 +13,3 @@ function enableCache(cached) {

var cls = this
var fn = validFunc(cls.prototype[method], method)
var fn = isValidFunc(cls.prototype[method], method)
key = key || cached.DEFAULT_PROTO_KEY.replace('{_fn_}', fn[_REALNAME])

@@ -26,3 +26,3 @@ hiddenProperty(fn, _REALNAME, fn.name || method)

}
fn = validFunc(cls[method], method)
fn = isValidFunc(cls[method], method)
key = key || cached.DEFAULT_KEY.replace('{_fn_}', fn[_REALNAME])

@@ -51,6 +51,40 @@ hiddenProperty(fn, _REALNAME, fn.name || method)

Cached.prototype._initClassHelper = function() {
/**
* Revive object from a json string
*/
function reviver(k, v) {
if ('object' == typeof v && v !== null && !Array.isArray(v)) {
var cls = v[_REALNAME]
if (cls) {
if (!(cls in constructors)) {
log('Constructor for %s doesn\'t exist anymore.', cls)
// return a undefined, mean this object is not available anymore
return
}
cls = constructors[cls]
delete v[_REALNAME]
v = new cls(v)
if (v._unpickle) {
v._unpickle()
}
}
return v
}
if ('string' === typeof v && RE_JSON_TIME.test(v)) {
// revive a date object
v = new Date(v)
}
return v
}
function unpickle(value) {
return JSON.parse(value, reviver)
}
Cacheable.prototype._initClassHelper = function() {
this.helpers.enableCache = enableCache(this)
this.helpers.clearCache = clearCache(this)
this.helpers.addCacheKey = addCacheKey
this.unpickle = unpickle
}

@@ -61,3 +95,3 @@

*/
Cached.prototype.register = function(cls, modelName) {
Cacheable.prototype.register = function(cls, modelName) {
modelName = modelName || cls.modelName || cls.name

@@ -80,3 +114,3 @@ hiddenProperty(cls, _REALNAME, modelName)

*/
Cached.prototype._extend = function extendClass(cls) {
Cacheable.prototype._extend = function extendClass(cls) {
var cached = this, proto = cls.prototype

@@ -111,14 +145,8 @@ cls.classCacheKeys = []

Cached.prototype.pickle = function pickle(value) {
return JSON.stringify(value)
}
Cached.prototype.unpickle = function unpickle(value) {
return JSON.parse(value, reviver)
function hiddenProperty(where, property, value) {
Object.defineProperty(where, property, { value: value });
}
/**
* Constructor function helpers
*/
function validFunc(fn, method) {
function isValidFunc(fn, method) {
if (!fn) {

@@ -134,34 +162,1 @@ throw new Error('method "' + method + '" not defined')

/**
* How to stringify an object when load data from redis
*/
function reviver(k, v) {
if (k === '' && v && 'object' == typeof v) {
var cls = v[_REALNAME]
if (cls) {
if (!(cls in constructors)) {
log('Constructor for %s doesn\'t exist anymore.', cls)
// return a undefined, mean this object is not available anymore
return
}
cls = constructors[cls]
delete v[_REALNAME]
v = new cls(v)
if (v._unpickle) {
v._unpickle()
}
}
return v
}
if ('string' === typeof v && RE_JSON_TIME.test(v)) {
// revive a date object
v = new Date(v)
}
return v
}
function hiddenProperty(where, property, value) {
Object.defineProperty(where, property, { value: value });
}
{
"name": "cacheable",
"version": "0.2.0",
"version": "0.2.4",
"description": "A cache wrapper with redis",

@@ -10,4 +10,8 @@ "main": "index.js",

"dependencies": {
"debug": "0.7.x"
"debug": "0.7.x",
"storeman": "~0.0.1"
},
"devDependencies": {
"mocha": "*"
},
"repository": {

@@ -14,0 +18,0 @@ "type": "git",

@@ -185,9 +185,5 @@ # Cacheable

## TODO
Make this package compatible with other cache backend, rather than only redis right now.
## License
the MIT licence.
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