#27882: Allow template fragment caching for unlimited time
--------------------------------------+------------------------------------
     Reporter:  MikiSoft              |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Template system       |                  Version:  1.10
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  1                     |      Needs documentation:  0
  Needs tests:  1                     |  Patch needs improvement:  0
Easy pickings:  1                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

 * has_patch:  0 => 1
 * needs_tests:  0 => 1
 * easy:  0 => 1
 * stage:  Unreviewed => Accepted


Comment:

 [https://docs.djangoproject.com/en/stable/topics/cache/#basic-usage The
 documentation] says, "Passing in `None` for `timeout` will cache the value
 forever. A timeout of 0 won’t cache the value." So `{% cache %}` needs to
 allow `None`. It looks like this patch does the trick:
 {{{ #!diff
 diff --git a/django/templatetags/cache.py b/django/templatetags/cache.py
 index 3af6dc4..9e402a1 100644
 --- a/django/templatetags/cache.py
 +++ b/django/templatetags/cache.py
 @@ -20,10 +20,11 @@ class CacheNode(Node):
              expire_time = self.expire_time_var.resolve(context)
          except VariableDoesNotExist:
              raise TemplateSyntaxError('"cache" tag got an unknown
 variable: %r' % self.expire_time_var.var)
 -        try:
 -            expire_time = int(expire_time)
 -        except (ValueError, TypeError):
 -            raise TemplateSyntaxError('"cache" tag got a non-integer
 timeout value: %r' % expire_time)
 +        if expire_time is not None:
 +            try:
 +                expire_time = int(expire_time)
 +            except (ValueError, TypeError):
 +                raise TemplateSyntaxError('"cache" tag got a non-integer
 timeout value: %r' % expire_time)
          if self.cache_name:
              try:
                  cache_name = self.cache_name.resolve(context)
 }}}
 A test and perhaps a documentation update is also required.

--
Ticket URL: <https://code.djangoproject.com/ticket/27882#comment:3>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.0b9812318f58427494acec40f10fec82%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to