Opened 4 years ago

Last modified 3 years ago

#32076 closed New feature

Adding async methods to BaseCache — at Version 1

Reported by: Andrew Chen Wang Owned by: nobody
Component: Core (Cache system) Version: dev
Severity: Normal Keywords: cache
Cc: Andrew Godwin, Carlton Gibson Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Andrew Chen Wang)

I've recently created a new package for Redis and Django integration at django-async-redis. I'd like to add the missing methods, e.g. get_async or set_async to the BaseCache so people can get type hints or autocompletion suggestions when using django.core.cache.cache with async.

Additionally, in order to be compatible with the async methods, there would need to be a new async method for closing cache connections/pools at django.core.cache.backends.base. I believe the only good solution to that would be:

async def close_caches_async(**kwargs):
    # Some caches -- python-memcached in particular -- need to do a cleanup at the
    # end of a request cycle. If not implemented in a particular backend
    # cache.close is a no-op
    for cache in caches.all():
        await cache.close_async()

Please let me know if that is out of scope though. I also believe implementing async methods for the current backends is also out of scope of this ticket (and my time :P). Edit: on second thought, I will add the methods to DummyCache as well.

For reference, the Google Group Discussion: here and here

Change History (1)

comment:1 by Andrew Chen Wang, 4 years ago

Description: modified (diff)
Version: 3.1master
Note: See TracTickets for help on using tickets.
Back to Top