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

LRUCache.set not update cache value when the key exists #560

Closed
CwjXFH opened this issue May 13, 2024 · 4 comments
Closed

LRUCache.set not update cache value when the key exists #560

CwjXFH opened this issue May 13, 2024 · 4 comments
Labels
contributions-welcome Happy to accept pull requests for this issue

Comments

@CwjXFH
Copy link

CwjXFH commented May 13, 2024

LRUCache.set does not update the cache value when the key exists, this may confuse the user. Why is it designed this way?

def set(self, key: K, value: V):
    if self.cache.get(key):
        self.cache.move_to_end(key, last=True)
    else:
        self.cache[key] = value
        if self.capacity is not None and self.length > self.capacity:
            self.cache.popitem(last=False)
@msiemens
Copy link
Owner

msiemens commented Oct 5, 2024

Good point! Would you like to contribute a bugfix on this?

@msiemens msiemens added the contributions-welcome Happy to accept pull requests for this issue label Oct 5, 2024
@CwjXFH
Copy link
Author

CwjXFH commented Oct 8, 2024

fix: #573

@msiemens
Copy link
Owner

Fixed in #573

@msiemens
Copy link
Owner

v4.8.2 includes this fix and has been released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributions-welcome Happy to accept pull requests for this issue
Projects
None yet
Development

No branches or pull requests

2 participants