Skip to content

Commit

Permalink
chore: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Dec 17, 2024
1 parent 58d9951 commit 76c11ae
Showing 1 changed file with 0 additions and 25 deletions.
25 changes: 0 additions & 25 deletions evmspec/data/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,30 +461,5 @@ async def get_logs(self) -> Tuple["Log", ...]:
class BlockHash(HexBytes32): ...


def ttl_cache(maxsize=128, ttl=600, timer=monotonic, typed=False):
"""Decorator to wrap a function with a memoizing callable that saves
up to `maxsize` results based on a Least Recently Used (LRU)
algorithm with a per-item time-to-live (TTL) value.
"""
if maxsize is None:
return _cache(_UnboundTTLCache(ttl, timer), None, typed)
elif callable(maxsize):
return _cache(TTLCache(128, ttl, timer), 128, typed)(maxsize)
else:
return _cache(TTLCache(maxsize, ttl, timer), maxsize, typed)


def _cache(cache, maxsize, typed):
# reimplement ttl_cache with no RLock for race conditions

def decorator(func):
key = keys.typedkey if typed else keys.hashkey
wrapper = cached(cache=cache, key=key, lock=None, info=True)(func)
wrapper.cache_parameters = lambda: {"maxsize": maxsize, "typed": typed}
return wrapper

return decorator


__str_new__ = str.__new__
__hb_new__ = HexBytes.__new__

0 comments on commit 76c11ae

Please sign in to comment.