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. 🙂
If the maximum number of cached requests is specified to the
setupCache
function, I would expect the oldest cache entry (by comparing theexpires
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
orRedisStore
, essentially item with the first key from the result ofObject.keys({ /* entries map */ })
, which is nondeterministic.I am wondering, is this expected? But it seems more like a bug. 🤔
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: https://github.com/RasCarlito/axios-cache-adapter/pull/248