#28601: do not cache default callable return value of None in get_or_set
--------------------------------------+------------------------------------
     Reporter:  Dan Tao               |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Core (Cache system)   |                  Version:  master
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  1                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Description changed by Dan Tao:

Old description:

> In [82be474
> https://github.com/django/django/commit/82be474efa81e5f2e127d711045a2ec06b206a8e]
> the change was made to allow None as a default value passed to
> BaseCache.get_or_set. In case the default value of None is used, it is
> not
> stored in the cache. This still left open the possibility that default
> could
> be a callable that returns None, in which case it would be stored in the
> cache.
>
> {{{
> # This scenario works as expected.
> cache.get_or_set('foo', None)  # None
> cache.get_or_set('foo', 5)  # 5
> cache.get('foo')  # 5
>
> # This scenario seems wrong.
> cache.get_or_set('bar', lambda: None)  # None
> cache.get_or_set('bar', 5)  # None :(
> cache.get('bar')  # None :(
> }}}

New description:

 In
 
[https://github.com/django/django/commit/82be474efa81e5f2e127d711045a2ec06b206a8e
 82be474] the change was made to allow None as a default value passed to
 BaseCache.get_or_set. In case the default value of None is used, it is not
 stored in the cache. This still left open the possibility that default
 could
 be a callable that returns None, in which case it would be stored in the
 cache.

 {{{
 # This scenario works as expected.
 cache.get_or_set('foo', None)  # None
 cache.get_or_set('foo', 5)  # 5
 cache.get('foo')  # 5

 # This scenario seems wrong.
 cache.get_or_set('bar', lambda: None)  # None
 cache.get_or_set('bar', 5)  # None :(
 cache.get('bar')  # None :(
 }}}

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28601#comment:4>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/062.836fc62bb96f779a5623d190473dc33f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to