[Python-ideas] Clear all caches

Alexander Walters tritium-list at sdamon.com
Wed Apr 1 16:58:44 CEST 2015


Why not just take a dbapi approach to this; define an api, build things 
to that api in the standard library, but leave it to third parties to 
use it.  "Does your module have a cache?  define these methods 
somewhere, and anything that manages cache will know how to deal with 
it".  No global registry, not global manager in the standard library, 
just an api.

On 4/1/2015 10:37, Andrew Barnert wrote:
> 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?
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/



More information about the Python-ideas mailing list