Comparing version 1.1.0 to 1.2.0
1.2.0 / 2017-07-18 | ||
================== | ||
* feat: support lru.keys (#2) | ||
1.1.0 / 2017-07-04 | ||
@@ -3,0 +8,0 @@ ================== |
23
index.js
@@ -67,2 +67,25 @@ 'use strict'; | ||
keys() { | ||
const cacheKeys = new Set(); | ||
const now = Date.now(); | ||
for (const entry of this.cache.entries()) { | ||
checkEntry(entry); | ||
} | ||
for (const entry of this._cache.entries()) { | ||
checkEntry(entry); | ||
} | ||
function checkEntry(entry) { | ||
const key = entry[0]; | ||
const item = entry[1]; | ||
if (entry[1].value && (!entry[1].expired) || item.expired >= now) { | ||
cacheKeys.add(key); | ||
} | ||
} | ||
return Array.from(cacheKeys.keys()); | ||
} | ||
_update(key, item) { | ||
@@ -69,0 +92,0 @@ this.cache.set(key, item); |
{ | ||
"name": "ylru", | ||
"description": "Extends LRU base on hashlru", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"homepage": "https://github.com/node-modules/ylru", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -67,4 +67,26 @@ # ylru | ||
### lru.keys() | ||
Get all unexpired cache keys from lru, due to the strategy of ylru, the `keys`' length may greater than `max`. | ||
```js | ||
const lru = new LRU(3); | ||
lru.set('key 1', 'value 1'); | ||
lru.set('key 2', 'value 2'); | ||
lru.set('key 3', 'value 3'); | ||
lru.set('key 4', 'value 4'); | ||
lru.keys(); // [ 'key 4', 'key 1', 'key 2', 'key 3'] | ||
// cache: { | ||
// 'key 4': 'value 4', | ||
// } | ||
// _cache: { | ||
// 'key 1': 'value 1', | ||
// 'key 2': 'value 2', | ||
// 'key 3': 'value 3', | ||
// } | ||
``` | ||
## License | ||
[MIT](LICENSE) |
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
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
7115
90
92
1