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

[RFC]: Replace memory_limit option with max_items #57

Closed
boesing opened this issue Jun 13, 2024 · 3 comments · Fixed by #60
Closed

[RFC]: Replace memory_limit option with max_items #57

boesing opened this issue Jun 13, 2024 · 3 comments · Fixed by #60
Labels
Milestone

Comments

@boesing
Copy link
Member

boesing commented Jun 13, 2024

RFC

Q A
Proposed Version(s) 3.0.0
BC Break? Dunno

Goal

As there were a bunch of complaints regarding the memory_limit option and since it is not properly working anyways, I'd propose replacing the memory_limit option with a max_items option instead.

Background

The calculation of free and used memory within PHP at runtime is not really working. Especially since there is no way (at least not in the way it is implemented right now) to calculate the only consumed memory from within the memory adapter.

Having max_items option allows users to either limit the cache to a specific amount of entries (to prevent memory from somehow overflowing - ofc that only works if a proper value is chosen) or just allows unlimited cache items.

Considerations

Users will have to modify their options to allow a certain amount/unlimited cache items in the memory adapter rather than defining a memory_limit.

Proposal(s)

Replace memory_limit with max_items. The adapter is not able to handle memory_limit in a meaningful way. Memory can be consumed outside of the memory adapter and lead to overflows as well and thus, I do not see a reason to have any memory limit handling in the memory adapter. Consumers should be aware that the memory adapter works the same way as a property cache, there won't be any "auto-free memory when memory_limit is close to overflow" and thus.

Having an option to limit cache items to a certain amount of items might help preventing an actual overflow from a count perspective but does not respect the cache item size in any way. But I guess thats absolutely okay and thats what people used to work with in symfony cache as well.

Appendix

Ref: https://symfony.com/doc/current/components/cache/adapters/array_cache_adapter.html
Ref: #56
Ref: #54
Ref: #5
Ref: #11
Ref: #7

@boesing boesing added the RFC label Jun 13, 2024
@boesing boesing added this to the 3.0.0 milestone Jun 13, 2024
@gsteel
Copy link
Member

gsteel commented Jun 13, 2024

Seems like the right approach to me 👍

Considering that the memory_limit option effectively can't work (?), could the relevant code be removed without breaking BC, and, could the max_items option be introduced in 2.x thereby leaving only the removal of the memory_limit option in 3.x

@boesing
Copy link
Member Author

boesing commented Jun 13, 2024

Yes, having item limit in v2 would be applicable.
Default would be infinite anyways and thus can work together with memory_limit.

@boesing
Copy link
Member Author

boesing commented Jun 15, 2024

Created #60 as a PoC

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

Successfully merging a pull request may close this issue.

2 participants