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

Open
CwjXFH opened this issue May 13, 2024 · 0 comments
Open

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

CwjXFH opened this issue May 13, 2024 · 0 comments

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)
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