undici icon indicating copy to clipboard operation
undici copied to clipboard

Add ability to detect when `MemoryCacheStore` reaches max size

Open OliverJAsh opened this issue 8 months ago • 6 comments

What is the problem this feature will solve?

Currently it's possible to configure a maxSize with MemoryCacheStore, but there doesn't seem to be any way to detect when this max size has been exceeded.

new Undici.cacheStores.MemoryCacheStore({
  maxSize: 100_000_000,
})

What is the feature you are proposing to solve the problem?

Add a mechanism to detect when the max size has been exceeded.

What alternatives have you considered?

No response

OliverJAsh avatar Apr 24 '25 13:04 OliverJAsh

An event (e.g. full) or a property (e.g. size getter) can be helpful here; but of curiosity, what use case are you looking exactly?

metcoder95 avatar Apr 30 '25 07:04 metcoder95

I simply want to know when the cache is full, so I can consider either increasing the max size or optimizing cache usage.

OliverJAsh avatar Apr 30 '25 08:04 OliverJAsh

Got it, would you like to send a PR for that?

metcoder95 avatar Apr 30 '25 08:04 metcoder95

I'd like to work on this. I'm thinking of adding a size getter, and an isFull method. Thoughts?

FelixVaughan avatar May 13 '25 15:05 FelixVaughan

Would it make sense to have an event for when the max size is reached?

OliverJAsh avatar May 13 '25 15:05 OliverJAsh

Yes, I believe this makes sense. Perhaps all three would be useful.

FelixVaughan avatar May 13 '25 18:05 FelixVaughan