Skip to content

Commit

Permalink
Undoing API change as it's breaking things
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Dec 5, 2018
1 parent 5378fdb commit 1a0c3b2
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 43 deletions.
13 changes: 0 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,6 @@ Removes item from cache
const staleItem = cache.remove("myKey");
```

## reset
### Method

Resets the cache to it's original state
return {Object} LRU instance
**Example**
```javascript
cache.reset();
```
## set
### Method

Expand Down
25 changes: 12 additions & 13 deletions lib/tiny-lru.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,33 @@
* @copyright 2018
* @license BSD-3-Clause
* @link https://github.com/avoidwork/tiny-lru
* @version 3.0.7
* @version 4.0.0
*/
"use strict";

(function (global) {
const next = typeof process !== "undefined" ? process.nextTick : arg => setTimeout(arg, 1),
empty = null;

function reset () {
this.cache = {};
this.first = empty;
this.last = empty;
this.length = 0;

return this;
}

class LRU {
constructor (max, notify, ttl) {
this.max = max;
this.notify = notify;
this.ttl = ttl;

return this.reset();
reset.call(this);
}

clear (silent = false) {
this.reset();
reset.call(this);

if (silent === false && this.notify === true) {
next(this.onchange("clear", this.dump()));
Expand Down Expand Up @@ -118,15 +126,6 @@
return result;
}

reset () {
this.cache = {};
this.first = empty;
this.last = empty;
this.length = 0;

return this;
}

set (key, value, silent = false, bypass = false) {
if (bypass === true || this.has(key) === true) {
const item = this.cache[key];
Expand Down
4 changes: 2 additions & 2 deletions lib/tiny-lru.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/tiny-lru.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tiny-lru",
"description": "Tiny LRU cache for Client or Server",
"version": "3.0.7",
"version": "4.0.0",
"homepage": "https://github.com/avoidwork/tiny-lru",
"author": "Jason Mulligan <jason.mulligan@avoidwork.com>",
"repository": {
Expand Down
9 changes: 9 additions & 0 deletions src/intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@
(function (global) {
const next = typeof process !== "undefined" ? process.nextTick : arg => setTimeout(arg, 1),
empty = null;

function reset () {
this.cache = {};
this.first = empty;
this.last = empty;
this.length = 0;

return this;
}
14 changes: 2 additions & 12 deletions src/lru.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
this.max = max;
this.notify = notify;
this.ttl = ttl;

return this.reset();
reset.call(this);
}

clear (silent = false) {
this.reset();
reset.call(this);

if (silent === false && this.notify === true) {
next(this.onchange("clear", this.dump()));
Expand Down Expand Up @@ -103,15 +102,6 @@
return result;
}

reset () {
this.cache = {};
this.first = empty;
this.last = empty;
this.length = 0;

return this;
}

set (key, value, silent = false, bypass = false) {
if (bypass === true || this.has(key) === true) {
const item = this.cache[key];
Expand Down

0 comments on commit 1a0c3b2

Please sign in to comment.