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

Inconsistent use of >= and > in constraint checks #49

Open
gurza opened this issue Sep 30, 2024 · 1 comment
Open

Inconsistent use of >= and > in constraint checks #49

gurza opened this issue Sep 30, 2024 · 1 comment

Comments

@gurza
Copy link

gurza commented Sep 30, 2024

Look at allowed() method implementation, https://vscode.dev/github/go-pkgz/lcw/blob/master/v2/expirable_cache.go#L156
The maxKeys and maxValueSize checks use the >= operator, while the maxKeySize check uses >.

In Get() method, https://vscode.dev/github/go-pkgz/lcw/blob/master/v2/expirable_cache.go#L80 uses >= operator.

This inconsistency could lead to off-by-one errors or unexpected behavior depending on the intended constraint enforcement.

Which comparison operator should be consistently used across all constraint checks?

I can help standardize the comparison operators. Let me know your preference, and I can submit a pull request.

@paskal
Copy link
Collaborator

paskal commented Sep 30, 2024

Could you please describe a scenario where it might be a problem? I'm hesitating about changing it as it would be a breaking change of behaviour, the limit behaviour would change for all users of the module and it might break something in tests as well as in production code.

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

2 participants