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

Remove lru-dict dependency #2884

Closed
Tracked by #2854
nlnw opened this issue Mar 19, 2023 · 2 comments · Fixed by #3196
Closed
Tracked by #2854

Remove lru-dict dependency #2884

nlnw opened this issue Mar 19, 2023 · 2 comments · Fixed by #3196
Labels
Breaking Change v7 breaking changes considered for v7

Comments

@nlnw
Copy link

nlnw commented Mar 19, 2023

lru-dict requires a wheel that is not pre-compiled for Python 3.11.

It is only used in 1 place where it should be able to be replaced with the built-in functools lru cache: https://github.com/ethereum/web3.py/blob/master/web3/middleware/cache.py#L196

Removing this dependency would avoid future compatibility problems as well.

@fselmo
Copy link
Collaborator

fselmo commented Mar 21, 2023

Agreed. This could be cleaned up by using the internal SimpleCache class (as was done to the simple_cache_middleware when it was asynced) . I don't think this should be considered a breaking change since this would just be an implementation change for an internal cache class. I would be happy to review a PR that makes this change otherwise I can get to it sometime soon. Thanks for the issue 👍🏼

@prathmeshranaut
Copy link
Contributor

Popping first item from OrderedDict(SimpleCache) vs lru cache could be considered a breaking change for some applications.

def cache(self, key: str, value: Any) -> Tuple[Any, Dict[str, Any]]:
evicted_items = None
# If the key is already in the OrderedDict just update it
# and don't evict any values. Ideally, we could still check to see
# if there are too many items in the OrderedDict but that may rearrange
# the order it should be unlikely that the size could grow over the limit
if key not in self._data:
while len(self._data) >= self._size:
if evicted_items is None:
evicted_items = {}
k, v = self._data.popitem(last=False)
evicted_items[k] = v
self._data[key] = value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking Change v7 breaking changes considered for v7
Projects
None yet
3 participants