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

Add maxAge option #27

Merged
merged 49 commits into from
Jan 14, 2021
Merged

Conversation

javi11
Copy link
Contributor

@javi11 javi11 commented Nov 25, 2020

Add a lazy max-age implementation that lacy removes expired items on get, peek, or has method calls. Hope the implementation fits on your library :).

Closes #18

Add a lazy max age implementation that remove expired items on get, peek or has method calls
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.test-d.ts Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
@sindresorhus sindresorhus changed the title feat: add maxAge implementation Add maxAge option Nov 25, 2020
- Use Date.now()
- Prefix max Age test
@javi11
Copy link
Contributor Author

javi11 commented Nov 25, 2020

Done ;). Thanks for the comments

@sindresorhus
Copy link
Owner

Can you fix the merge conflict?

index.d.ts Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
@sindresorhus
Copy link
Owner

In the has() method. Boolean(cache.get(...)) is not the same as cache.has(...).

@javi11
Copy link
Contributor Author

javi11 commented Nov 25, 2020

In the has() method. Boolean(cache.get(...)) is not the same as cache.has(...).

mm depending what we want if we want that has return true for items that has been expired we can remove that part, but if has will return false for expired elements, there is the need to get the element first to verify the expiration time :S

@sindresorhus
Copy link
Owner

Can you do a test where maxAge option is set, the value is set to undefined (which is different from no key being there), and using .has(). It looks like that will be a false-positive.

index.js Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
- Clean the code
- Rename tests
- Change max age description
index.d.ts Outdated Show resolved Hide resolved
index.d.ts Outdated Show resolved Hide resolved
index.d.ts Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
@javi11
Copy link
Contributor Author

javi11 commented Jan 12, 2021

Done, I called the set option maxAge to options = { maxAge } and set maxAge globaly by default Infinity instead of 0 that sure it makes more sense ;)

index.d.ts Outdated Show resolved Hide resolved
index.d.ts Outdated Show resolved Hide resolved
index.d.ts Outdated Show resolved Hide resolved
index.d.ts Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
javi11 and others added 7 commits January 12, 2021 15:55
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
@sindresorhus sindresorhus merged commit 85f49e2 into sindresorhus:master Jan 14, 2021
@javi11 javi11 deleted the feat/add-max-age branch January 26, 2021 14:56
aleclarson pushed a commit to aleclarson/quick-lru that referenced this pull request Apr 6, 2021
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
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.

Support max-age
3 participants