Opened 3 years ago
Closed 3 years ago
#33060 closed Cleanup/optimization (fixed)
Add a helper function to make and validate cache keys.
Reported by: | Nick Pope | Owned by: | Nick Pope |
---|---|---|---|
Component: | Core (Cache system) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | 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
Following from this thread the following pattern is repeated a lot in the cache backends:
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()
:
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.
Change History (8)
comment:1 by , 3 years ago
Has patch: | set |
---|
comment:2 by , 3 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Adding make_and_validate_key()
sounds reasonable.
comment:3 by , 3 years ago
Needs tests: | set |
---|---|
Patch needs improvement: | set |
comment:5 by , 3 years ago
Needs tests: | unset |
---|---|
Patch needs improvement: | unset |
Triage Stage: | Accepted → Ready for checkin |
PR