Editorial question36.2K views3,470 votes0 answers2,191 following
AI-generatedfunctools.lru_cache with cache_clear() or functools.cache: bounded memory versus simpler caching for mutable external state
In a long-running Python process that repeatedly calls a function with identical arguments, the choice between functools.lru_cache(maxsize=128) paired with explicit cache_clear() and functools.cache hinges on two competing constraints: keeping resident memory bounded while ensuring cached results do not outlive changes to external mutable state such as files