Comparing version 1.0.0 to 1.1.0
1.1.0 / 2017-07-04 | ||
================== | ||
* feat: support get with maxAge (#1) | ||
1.0.0 / 2016-12-29 | ||
@@ -3,0 +8,0 @@ ================== |
20
index.js
@@ -11,9 +11,17 @@ 'use strict'; | ||
get(key) { | ||
get(key, options) { | ||
let item = this.cache.get(key); | ||
const maxAge = options && options.maxAge; | ||
if (item) { | ||
const now = Date.now(); | ||
// check expired | ||
if (item.expired && Date.now() > item.expired) { | ||
if (item.expired && now > item.expired) { | ||
item.expired = 0; | ||
item.value = undefined; | ||
} else { | ||
// update expired in get | ||
if (maxAge !== undefined) { | ||
const expired = maxAge ? now + maxAge : 0; | ||
item.expired = expired; | ||
} | ||
} | ||
@@ -26,4 +34,5 @@ return item.value; | ||
if (item) { | ||
const now = Date.now(); | ||
// check expired | ||
if (item.expired && Date.now() > item.expired) { | ||
if (item.expired && now > item.expired) { | ||
item.expired = 0; | ||
@@ -34,2 +43,7 @@ item.value = undefined; | ||
this._update(key, item); | ||
// update expired in get | ||
if (maxAge !== undefined) { | ||
const expired = maxAge ? now + maxAge : 0; | ||
item.expired = expired; | ||
} | ||
} | ||
@@ -36,0 +50,0 @@ return item.value; |
{ | ||
"name": "ylru", | ||
"description": "Extends LRU base on hashlru", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"homepage": "https://github.com/node-modules/ylru", | ||
@@ -15,3 +15,2 @@ "repository": { | ||
"egg-bin": "^1.10.0", | ||
"egg-ci": "^1.1.0", | ||
"eslint": "^3.12.2", | ||
@@ -39,6 +38,3 @@ "eslint-config-egg": "^3.2.0", | ||
}, | ||
"ci": { | ||
"version": "4, 6, 7" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -44,3 +44,4 @@ # ylru | ||
lru.set(key2, value2, { maxAge: 5000 }); | ||
lru.get(key2); | ||
// get key and update expired | ||
lru.get(key2, { maxAge: 5000 }); | ||
``` | ||
@@ -54,4 +55,6 @@ | ||
### lru.get(key) => value | null | ||
### lru.get(key[, options]) => value | null | ||
- `{Number} options.maxAge`: update expire time when get, value will become `undefined` after `maxAge` pass. | ||
Returns the value in the cache. | ||
@@ -58,0 +61,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
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
6088
8
72
70