think-cache
Advanced tools
Comparing version 1.0.3 to 1.0.4
34
cache.js
@@ -14,19 +14,19 @@ const assert = require('assert'); | ||
*/ | ||
function thinkCache(name, value, config){ | ||
function ThinkCache(name, value, config) { | ||
assert(name && helper.isString(name), 'cache.name must be a string'); | ||
if(this.config){ | ||
if (this.config) { | ||
config = helper.parseAdapterConfig(this.config('cache'), config); | ||
}else{ | ||
} else { | ||
config = helper.parseAdapterConfig(config); | ||
} | ||
const handle = config.handle; | ||
assert(helper.isFunction(handle), 'cache.handle must be a function'); | ||
const Handle = config.handle; | ||
assert(helper.isFunction(Handle), 'cache.handle must be a function'); | ||
delete config.handle; | ||
const instance = new handle(config); | ||
//delete cache | ||
if(value === null){ | ||
const instance = new Handle(config); | ||
// delete cache | ||
if (value === null) { | ||
return Promise.resolve(instance.delete(name)); | ||
} | ||
//get cache | ||
if(value === undefined){ | ||
// get cache | ||
if (value === undefined) { | ||
return debounceInstance.debounce(name, () => { | ||
@@ -36,8 +36,8 @@ return instance.get(name); | ||
} | ||
//get cache when value is function | ||
if(helper.isFunction(value)){ | ||
// get cache when value is function | ||
if (helper.isFunction(value)) { | ||
return debounceInstance.debounce(name, () => { | ||
let cacheData; | ||
return instance.get(name).then(data => { | ||
if(data === undefined){ | ||
if (data === undefined) { | ||
return value(name); | ||
@@ -47,3 +47,3 @@ } | ||
}).then(data => { | ||
if(data !== undefined){ | ||
if (data !== undefined) { | ||
cacheData = data; | ||
@@ -54,9 +54,9 @@ return instance.set(name, data); | ||
return cacheData; | ||
}) | ||
}); | ||
}); | ||
} | ||
//set cache | ||
// set cache | ||
return Promise.resolve(instance.set(name, value)); | ||
} | ||
module.exports = thinkCache; | ||
module.exports = ThinkCache; |
@@ -16,2 +16,2 @@ const thinkCache = require('./cache.js'); | ||
} | ||
} | ||
}; |
{ | ||
"name": "think-cache", | ||
"description": "Cache for ThinkJS", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"author": { | ||
@@ -10,4 +10,5 @@ "name": "welefen", | ||
"scripts": { | ||
"test": "eslint index.js && nyc ava test/", | ||
"coverage": "nyc ava test/index.js && nyc report --reporter=html" | ||
"lint": "eslint --fix index.js & eslint --fix cache.js", | ||
"test": "npm run lint && nyc ava test/", | ||
"coverage": "npm test && nyc report --reporter=html" | ||
}, | ||
@@ -30,3 +31,4 @@ "contributors": [ | ||
"coveralls": "^2.11.16", | ||
"eslint": "2.8.0", | ||
"eslint": "~4.2.0", | ||
"eslint-config-think": "~1.0.1", | ||
"nyc": "^7.1.0" | ||
@@ -33,0 +35,0 @@ }, |
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
146
0
6957
7