Skip to content

Commit

Permalink
Address code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kibertoad committed Mar 13, 2023
1 parent 9b8d9a8 commit a9a478a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Gets cached item and moves it to the front
const item = cache.get("myKey");
```

## getExpirationTime
## expiresAt
### Method

Gets expiration time for cached item
Expand All @@ -95,7 +95,7 @@ Gets expiration time for cached item
**Example**

```javascript
const item = cache.getExpirationTime("myKey");
const item = cache.expiresAt("myKey");
```

## keys
Expand Down
2 changes: 1 addition & 1 deletion src/lru.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class LRU {
return result;
}

getExpirationTime (key) {
expiresAt (key) {
let result;

if (this.#has(key)) {
Expand Down
14 changes: 5 additions & 9 deletions test/lru.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,10 @@ describe("Testing functionality", function () {
assert.equal(this.cache.size, 0, "Should be 'null'");
});

it("It should return expiration time", function () {
const ttl = 99999;
this.cache = lru(1, ttl);
const now = new Date();
this.cache.set("key", "value");
const expirationTime = this.cache.getExpirationTime("key");
const remainingTime = expirationTime - now.getTime();
// keep 100 msec margin of error just in case
assert.equal(99999 - remainingTime < 100, true, "Should be within a margin of error");
it("It should expose expiration time", function () {
this.cache = lru(1, 6e4);
this.cache.set(this.items[0], false);
assert.equal(typeof this.cache.expiresAt(this.items[0]), "number", "Should be a number");
assert.equal(this.cache.expiresAt("invalid"), undefined, "Should be undefined");
});
});

0 comments on commit a9a478a

Please sign in to comment.