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 d646940 commit 5378fdb
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 27 deletions.
24 changes: 13 additions & 11 deletions lib/tiny-lru.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,25 @@
* @copyright 2018
* @license BSD-3-Clause
* @link https://github.com/avoidwork/tiny-lru
* @version 3.0.6
* @version 3.0.7
*/
"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;
reset.call(this);

return this.reset();
}

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

if (silent === false && this.notify === true) {
next(this.onchange("clear", this.dump()));
Expand Down Expand Up @@ -125,6 +118,15 @@
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.6",
"version": "3.0.7",
"homepage": "https://github.com/avoidwork/tiny-lru",
"author": "Jason Mulligan <jason.mulligan@avoidwork.com>",
"repository": {
Expand Down
9 changes: 0 additions & 9 deletions src/intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,3 @@
(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: 12 additions & 2 deletions src/lru.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
this.max = max;
this.notify = notify;
this.ttl = ttl;
reset.call(this);

return this.reset();
}

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

if (silent === false && this.notify === true) {
next(this.onchange("clear", this.dump()));
Expand Down Expand Up @@ -102,6 +103,15 @@
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 5378fdb

Please sign in to comment.