Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Invalidate oldest cache entry when exceeding store limit #247

Open
zhenwenc opened this issue May 19, 2021 · 1 comment
Open

Invalidate oldest cache entry when exceeding store limit #247

zhenwenc opened this issue May 19, 2021 · 1 comment

Comments

@zhenwenc
Copy link

zhenwenc commented May 19, 2021

If the maximum number of cached requests is specified to the setupCache function, I would expect the oldest cache entry (by comparing the expires value in each stored item) will be removed from the store when the store size is reaching the limit.

However, a random entry in the cache will be removed instead when using the built-in MemoryStore or RedisStore, essentially item with the first key from the result of Object.keys({ /* entries map */ }), which is nondeterministic.

I am wondering, is this expected? But it seems more like a bug. 🤔

// Related option for `setupCache()`
{
  // {Number} Maximum number of cached request (last in, first out queue system),
  // defaults to `false` for no limit. *Cannot be overridden per request*
  limit: false,
}

Note that you can reproduce the issue with the modified test cases in my linked PR below. 🙂

PR for the fix: PR for the fix: #248

@zhenwenc zhenwenc changed the title Oldest cache doesn't get invalidated when exceeding store limit Invalidate oldest cache entry when exceeding store limit May 19, 2021
@zhenwenc
Copy link
Author

Bump

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

No branches or pull requests

1 participant