Skip to content

[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

Merged
merged 1 commit into from
Sep 24, 2016

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Sep 23, 2016

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.

return $this->namespace.$key;
}
if (strlen($id = $this->namespace.$key) > $this->maxIdLength) {
$id = $this->namespace.substr_replace(base64_encode(md5($key, true)), ':', -2);
Copy link
Member Author

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.

Copy link
Member Author

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)) {
Copy link
Member Author

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 :)

Copy link
Contributor

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).':';
Copy link
Member Author

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

@fabpot
Copy link
Member

fabpot commented Sep 24, 2016

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 11f448f into symfony:master Sep 24, 2016
fabpot added a commit that referenced this pull request Sep 24, 2016
…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
@nicolas-grekas nicolas-grekas deleted the cache-key-length branch September 29, 2016 10:06
@fabpot fabpot mentioned this pull request Oct 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants