Skip to content

Conversation

@gamazeps
Copy link

@gamazeps gamazeps commented Sep 6, 2017

Push are O(1) operations whereas shift are O(n) operations, this removes this complexity.

Also returns a null as the comment says


// Cached entry not at top of cache, move it to the top
if (cacheIndex > 0) {
entries.slice(cacheIndex, 1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a no-op

const entry = entries[cacheIndex]

// Cached entry not at top of cache, move it to the top
if (cacheIndex > 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to use cacheIndex !== entries.length - 1

@heydiplo
Copy link
Contributor

heydiplo commented Apr 2, 2018

@gamazeps,

With LRU we want most recent entry at the top of a cache (at 0, so it's searched first), that's why unshift.

null might be a valid return value we want to cache, undefined suits better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants