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

ylru

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ylru - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

5

History.md
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;

6

package.json
{
"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 @@

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