Skip to main content

python-lru-cache

#post

python-lru-cache

Saw this:

@lru_cache(maxsize=1)
@pyrolog.log_duration(slogger, "preparing go_terms")
def get_go_term_data() -> pd.DataFrame:
    # ...
  • learn about lru_cache
  • how does maxsize=1 help?
  • when would this help in general?
  • when would this NOT be a good idea in general?
  • I think functools.cache may be recent syntax sugar for functools.lru_cache(maxsize=None)…when to choose which?
  • When to use this instead of diskcache (which requires extra calls)? When is this good enough?
    • Is this good when just caching in memory for current session?
    • While diskcache is for caching indefinitely?

Caching in Python Using the LRU Cache Strategy – Real Python