Uh oh!
There was an error while loading. Please reload this page.
Use sha1 to reduce the risk of collisions - #12
Conversation
sagikazarmark
commented
Aug 1, 2016
Maybe we can make this configurable? Valid values are the results of |
GrahamCampbell
commented
Aug 1, 2016
Maybe we should just allow people to implement a key generator interface and inject that into the constructor and have it do |
Hm, okay, but I would be happier if we could make it kind of optional: add a hash option in config defaulting to sha1, allowed values are null and result of hash_algos. (createCacheKey in null case should throw a LogicException if no hash and no CacheKeyGenerator instances are provided). Also, a custom CacheKeyGenerator (name ok?) that could be provided via a setter (with a HashCacheKeyGenerator implementation used as the default). IMO in most cases such implementation might be an overkill, so I think it would be better to provide a "fallback"/default solution. WDYT? |
GrahamCampbell
commented
Aug 1, 2016
Why would anyone want to customize this? If they do, a CacheKeyGenerator would be fine? |
GrahamCampbell
commented
Aug 1, 2016
PS I really dislike setters. I prefer things to be immutable after instantiation. |
Me too, but considering that this adds an extra configuration effort, this seems to be a half-way solution to me. Also, changing the constructor would be a BC break (unless the generator is optional?), while adding an extra config option and an optionally used setter is not. |
GrahamCampbell
commented
Aug 1, 2016
I was thinking making it optional, with a default value of null, then filling it using a ternary statement, yeh. |
GrahamCampbell
commented
Aug 1, 2016
Hmm, just looked at the constructor signature. I think using the options resolver might be better. |
sagikazarmark
commented
Aug 1, 2016
Hmm, right. You can still fall back to a string then using the hash implementation? |
GrahamCampbell
commented
Aug 1, 2016
I've implemented the hash algo selection. How does that look? |
| return $next($request)->then(function (ResponseInterface $response) use ($cacheItem) { | ||
| if ($this->isCacheable($response)) { | ||
| if ($this->isCacheable($response) && ($maxAge = $this->getMaxAge($response)) > 0) { |
There was a problem hiding this comment.
Doing this from the github online editor, lol.
sagikazarmark
commented
Aug 1, 2016
Can you please add change log? We follow keep a change log format. |
GrahamCampbell
commented
Aug 1, 2016
Wanted to avoid conflicts with other PRs. Do you mind adding something on merge? |
Nyholm
commented
Aug 2, 2016
Thank you. 👍 |
sagikazarmark
commented
Aug 2, 2016
Looks good to me, thanks @GrahamCampbell |
egeloen
commented
Aug 5, 2016
I'm a little bit late here but this PR is a BC break in a minor version. All my caches are become broken due to the new hash algo used for the cache key generation. @sagikazarmark Can you confirm it has been done by mistake? Anyway, as the new tag has been released, let it as it is, I just need to change my cache config. |
GrahamCampbell
commented
Aug 5, 2016
I don't think it would be considered broken to just loose items from the cache? |
dbu
commented
Aug 5, 2016
did you get errors, or just cache misses? i think cache misses on a minor version sound ok. i hope we did not release it as a patch release though, that would be unexpected. |
sagikazarmark
commented
Aug 5, 2016
I agree, cache misses doesn't sound like BC break. |
Yes, I probaby abuse when saying BC break as technically everything is working fine (just differently)... I use it in a specific context: caching http requests done to a third service secured by IPs and use the generated cache for tests execution on Travis but after upgrading, my cache is becomes broken. As already said, not a big deal to fix, just want to discuss your BC policy. |
Nyholm
commented
Aug 5, 2016
That is an interesting question. Our general BC promise is here: http://php-http.readthedocs.io/en/latest/httplug/backwards-compatibility.html But should we consider the cache keys as a part of the BC promise? Whatever we decide should be documented. I suggest that we are allowed to update the cache keys for minor versions but not for patches. But I would try to avoid it. For the record: |
I would say the following : Do not make our keys part of our BC promise, but consider them as it was the case. |
sagikazarmark
commented
Aug 6, 2016
Actually this specific PR could even be a bugfix: with massive usage it's possible that some requests collide using md5. |
What's in this PR?
Switches the key generation algorithm over to use
sha1rather thanmd5.Why?
The performance is similar, and the collision risk is lower.
Example Usage
Checklist
To Do