-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Cache] Handle arbitrary key length when the backend cant using hashing #20037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
return $this->namespace.$key; | ||
} | ||
if (strlen($id = $this->namespace.$key) > $this->maxIdLength) { | ||
$id = $this->namespace.substr_replace(base64_encode(md5($key, true)), ':', -2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Namespace excluded, this is always 23 chars long, trailing padding =
removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The added trailing :
is to prevent any collision between hashed keys and non-hasked keys.
@@ -37,9 +37,9 @@ public function __construct($namespace = '', $defaultLifetime = 0, $version = nu | |||
if (null !== $version) { | |||
CacheItem::validateKey($version); | |||
|
|||
if (!apcu_exists($version.':'.$namespace)) { | |||
if (!apcu_exists($version.'@'.$namespace)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just because :
is a nice separator for namespace, thus had to change here. @
looks good also for version :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's all about the looks ;)
protected function __construct($namespace = '', $defaultLifetime = 0) | ||
{ | ||
$this->namespace = '' === $namespace ? '' : $this->getId($namespace); | ||
$this->namespace = '' === $namespace ? '' : $this->getId($namespace).':'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:
is a reserved char per psr6 so we use it internally to be free from any collision when concatenating keys and namespace later on
Thank you @nicolas-grekas. |
…ant using hashing (nicolas-grekas) This PR was merged into the 3.2-dev branch. Discussion ---------- [Cache] Handle arbitrary key length when the backend cant using hashing | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Saving some bits from #19521 :) Already awaited by PdoAdapter which defines the property. Commits ------- 11f448f [Cache] Handle arbitrary key length when the backend cant using hashing
Saving some bits from #19521 :) Already awaited by PdoAdapter which defines the property.