[Python-ideas] Clear all caches

Serhiy Storchaka storchaka at gmail.com
Wed Apr 1 14:28:39 CEST 2015


There are a lot of implicit caches in the stdlib. Some of them can grow 
unlimitedly. It would be good to have an official way to clear caches.

I proposed to add two functions (in some existing lightweight module or 
add a new module):

clear_caches(level=0)
register_cache(level, clear_func)

clear_caches() calls cache clearing functions for specified level and 
larger.

register_cache() registers cache clearing functions for specified level. 
All modules that use implicit cache should register clearing function. 
functools.lru_cache() should register wrapper's cache clearing function. 
May be register gc.collect too. Third-party libraries and user code will 
be able to register their own clearing functions.



More information about the Python-ideas mailing list