Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When cache contains 2 items updating the first creates a reference loop in the second #5

Closed
avoidwork opened this issue Apr 11, 2017 · 0 comments
Assignees
Labels

Comments

@avoidwork
Copy link
Owner

avoidwork commented Apr 11, 2017

Noticed while fixing #4

> const cache = require("./lib/tiny-lru.es6")(10);
undefined
> cache.set('1', 'a');
LRU {
  cache: { '1': { next: null, previous: null, value: 'a' } },
  first: '1',
  last: '1',
  length: 1,
  max: 10,
  notify: false,
  onchange: [Function],
  update: [Function] }
> cache.set('2', 'b');
LRU {
  cache: 
   { '1': { next: '2', previous: null, value: 'a' },
     '2': { next: null, previous: '1', value: 'b' } },
  first: '2',
  last: '1',
  length: 2,
  max: 10,
  notify: false,
  onchange: [Function],
  update: [Function] }
> cache.set('1', 'c');
LRU {
  cache: 
   { '1': { next: null, previous: '2', value: 'c' },
     '2': { next: '1', previous: '1', value: 'b' } },
  first: '1',
  last: '2',
  length: 2,
  max: 10,
  notify: false,
  onchange: [Function],
  update: [Function] }

The previous value of '2' should be null in this case, and not '1'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant