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

Allow invalidation of entries based upon a capacity target #471

Closed
cetra3 opened this issue Dec 18, 2024 · 1 comment
Closed

Allow invalidation of entries based upon a capacity target #471

cetra3 opened this issue Dec 18, 2024 · 1 comment

Comments

@cetra3
Copy link

cetra3 commented Dec 18, 2024

I'll try my best to explain the scenario.

We have a cache that stores files as Byte values and we set the weigher as Bytes::len() and the max capacity to some number of bytes (i.e, 1gb or something).

When populating the cache either with try_get_with or insert, or whatever, there is a point in time where new memory is allocated in either the init future, or equivalent.

So what ends up happening is that your total size in memory of the cache is roughly equal to:

max_capacity + memory of init futures

When those init futures resolve, an eviction happens, and memory goes down. But for a period of time, there can be a lot of overhead in those init futures.

What I think might work is that, since within the init futures we know what the size of the thing will be when it goes in the cache before allocating, if we could say to the cache something like "evict up to n amount of capacity", then it would allow us to keep memory under control.

Something like:

cache.invalidate(capacity_num)

Let me know if that doesn't make sense, or there are any alternatives

@cetra3
Copy link
Author

cetra3 commented Dec 20, 2024

Just to update this: I've managed to work around this by using a shared semaphore in the init futures. I still think it might be valuable to have a way to resize the cache dynamically, but I will close this ticket off.

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

No branches or pull requests

1 participant