[Python-ideas] Clear all caches
Andrew Barnert
abarnert at yahoo.com
Wed Apr 1 16:37:31 CEST 2015
On Apr 1, 2015, at 06:41, Serhiy Storchaka <storchaka at gmail.com> wrote:
>
>> On 01.04.15 16:27, Paul Moore wrote:
>>> On 1 April 2015 at 13:28, Serhiy Storchaka <storchaka at gmail.com> wrote:
>>> 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.
I can see this being useful as just a way of standardizing an API for third-party modules that have a cache-clearing function. If there are a lot of them, having most of them do it the same way would make them easier to discover.
>> I'm not sure I understand how "level" would be used. Presumably
>> anything registering a cache has to decide what level it wants to be
>> at, but how should it decide? Maybe there should be some standard
>> levels defined? Is there actually a need for a level parameter at all?
>
> All this can be discussed here. It is just an idea, I'm not sure about any details. Right now the level parameter is not needed to me, but may be other developers will need it.
>
> May be the behavior should be opposite: clear caches of specified level and *lower*. Then by default only level 0 will be cleared and users will be able to use higher levels for long-living caches.
Higher vs. lower doesn't really matter that much; you can just define short, medium, and long as 0, -1, -2 instead of 0, 1, 2, right? (I think that, even if you don't define standard levels by name as Paul Moore suggests, you're still going to be doing so implicitly by the levels you choose in the stdlib...)
Anyway, why do you want this? Is there some cache that's using too much memory in an app of yours? Or is it more about getting a semi-clean start on the interactive interpreter? Or something different?
And which of the implicit caches all over the stdlib made you want this (since the stdlib was your motivating example)?
Also, this seems like something that other platforms (special-purpose math languages, interactive SQL interpreters, etc.) might have. If so, have you looked around to see how they do it?
More information about the Python-ideas
mailing list