#32076: Adding async methods to Base, Dummy, and LocMem cache backends
-------------------------------------+-------------------------------------
     Reporter:  Andrew Chen Wang     |                    Owner:  Andrew
                                     |  Chen Wang
         Type:  New feature          |                   Status:  assigned
    Component:  Core (Cache system)  |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  cache                |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Andrew Chen Wang:

Old description:

> I've recently created a new package for Redis and Django integration at
> [https://github.com/Andrew-Chen-Wang/django-async-redis 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
> [https://github.com/django/django/blob/999cddd58d30469f3ee85278985313fdf528323d/django/core/cache/__init__.py#L116-L121
> 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:
> [https://groups.google.com/forum/#!topic/django-developers/sGq5Bnc2JMg
> here] and [https://groups.google.com/forum/#!topic/django-
> developers/NX03LNahZPo here]

New description:

 I've recently created a new package for Redis and Django integration at
 [https://github.com/Andrew-Chen-Wang/django-async-redis 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
 
[https://github.com/django/django/blob/999cddd58d30469f3ee85278985313fdf528323d/django/core/cache/__init__.py#L116-L121
 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:
 [https://groups.google.com/forum/#!topic/django-developers/sGq5Bnc2JMg
 here] and [https://groups.google.com/forum/#!topic/django-
 developers/NX03LNahZPo here]

 Edit: I've decided to add the three main cache backends -- BaseCache,
 DummyCache, LocMemCache -- with the necessary test cases which can be used
 for all future async test cases for stuff like DBCache. Please read the
 latest commit for which test cases are notable exceptions to the main
 BaseCacheTests mixin.

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32076#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/074.4bea4d317d89207cb9c0d6bef1d1e09b%40djangoproject.com.

Reply via email to