Comparing version 0.2.0 to 0.3.0
27
index.js
'use strict'; | ||
const path = require('path'); | ||
const Conf = require('conf'); | ||
const pkgUp = require('pkg-up'); | ||
const parentDir = path.dirname(module.parent.filename); | ||
class CacheConf extends Conf { | ||
constructor(options) { | ||
const pkgPath = pkgUp.sync(parentDir); | ||
options = Object.assign({ | ||
projectName: pkgPath && require(pkgPath).name // eslint-disable-line import/no-dynamic-require | ||
}, options); | ||
super(options); | ||
this.version = options.version; | ||
} | ||
get(key) { | ||
@@ -26,2 +42,3 @@ if (this.isExpired(key)) { | ||
timestamp: opts.maxAge && Date.now() + opts.maxAge, | ||
version: this.version, | ||
data: key[k] | ||
@@ -33,2 +50,3 @@ }); | ||
timestamp: opts.maxAge && Date.now() + opts.maxAge, | ||
version: this.version, | ||
data: val | ||
@@ -55,3 +73,10 @@ }); | ||
return Boolean(item && item.timestamp && item.timestamp < Date.now()); | ||
if (!item) { | ||
return false; | ||
} | ||
const invalidTimestamp = item.timestamp && item.timestamp < Date.now(); | ||
const invalidVersion = item.version !== this.version; | ||
return Boolean(invalidTimestamp || invalidVersion); | ||
} | ||
@@ -58,0 +83,0 @@ } |
{ | ||
"name": "cache-conf", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Simple cache config handling for your app or module", | ||
@@ -42,3 +42,4 @@ "license": "MIT", | ||
"dependencies": { | ||
"conf": "^0.11.2" | ||
"conf": "^0.11.2", | ||
"pkg-up": "^1.0.0" | ||
}, | ||
@@ -45,0 +46,0 @@ "devDependencies": { |
@@ -65,2 +65,8 @@ # cache-conf [![Build Status](https://travis-ci.org/SamVerschueren/cache-conf.svg?branch=master)](https://travis-ci.org/SamVerschueren/cache-conf) | ||
###### version | ||
Type: `string` | ||
Version number of the data. If the version provided is not the same as the version of the cached data, the data will be invalid. | ||
#### isExpired(key) | ||
@@ -67,0 +73,0 @@ |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
5127
62
84
2
2
+ Addedpkg-up@^1.0.0