#33060: Add a helper function to make and validate cache keys.
-------------------------------------+-------------------------------------
               Reporter:  Nick Pope  |          Owner:  Nick Pope
                   Type:             |         Status:  assigned
  Cleanup/optimization               |
              Component:  Core       |        Version:  dev
  (Cache system)                     |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Following from
 [https://github.com/django/django/pull/14437#discussion_r696351175 this
 thread] the following pattern is repeated a lot in the cache backends:

 {{{#!python
         key = self.make_key(key, version=version)
         self.validate_key(key)
 }}}

 We can define a helper function on the base cache backend that can be used
 to avoid repetitiveness and help ensure that we consistently call
 `.validate_key()` after `.make_key()`:

 {{{#!python
     def make_and_validate_key(self, key, version=None):
         key = self.make_key(key, version=version)
         self.validate_key(key)
         return key
 }}}

 An alternative proposal is to have `.make_key()` learn a `validate` flag,
 but we'd probably need to have it as `False` by default for backward
 compatibility and we'd may still have issues if users have overridden
 `.make_key()`. So it would require documentation changes, release notes,
 and a deprecation period.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33060>
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/050.5784ef581c476e81618a817521fb83f5%40djangoproject.com.

Reply via email to