[Python-ideas] Unified style of cache management API

Brett Cannon brett at python.org
Thu Mar 28 13:45:09 EDT 2019


On Wed, Mar 27, 2019 at 10:34 AM Serhiy Storchaka <storchaka at gmail.com>
wrote:

> 27.03.19 15:46, Ma Lin пише:
> > re module [1] and struct module [2] have module-level cache for compiled
> > stuffs.
> > Other third-party modules may also need cache for something.
> >
> > Do we need an unified cache management API like this?
> > I suppose it's not mandatory, but welcome each module to use this API.
> >
> >    module.cache_get_capacity()     # return current capacity
> >    module.cache_set_capacity(100)  # set capacity
> >    module.cache_clear()            # clear cache
> >
> > Moreover, add these API to sys module, then the users can manage system
> > wide cache easily:
> >
> >    sys.cache_register(f)  # register a .cache_clear() function
> >    sys.cache_clear()      # call all registered .cache_clear()
>
> I proposed similar idea at 2015.
>
> https://mail.python.org/pipermail/python-ideas/2015-April/032836.html


So I would say that a cache-clearing function convention would be a
reasonable starting point. If that turns out to not be enough for folks we
can talk about expanding it, but I think we should start small and grow
from there as needed.

So what name would people want. clear_cache() or _clear_cache()? I
personally prefer the latter since clearing the cache shouldn't be
something people should typically need to do and thus the function is an
implementation detail.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190328/375b6951/attachment.html>


More information about the Python-ideas mailing list