lisaogren / axios-cache-adapter

Caching adapter for axios. Store request results in a configurable store to prevent unneeded network requests.
MIT License
725 stars 108 forks source link

Invalidate oldest cache entry when exceeding store limit #247

Open zhenwenc opened 3 years ago

zhenwenc commented 3 years ago

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: https://github.com/RasCarlito/axios-cache-adapter/pull/248

zhenwenc commented 3 years ago

Bump