-
Notifications
You must be signed in to change notification settings - Fork 202
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
Hash request URIs before using them as a cache key #181
Conversation
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.
@timrogers thanks for quickly turning this in!
Appreciate you listing the trade-offs of this approach, I believe we should be good in both cases but happy to reconsider at a future date if any issue arises.
There's just a small nit that makes Travis complain, I've left a comment below.
@@ -66,7 +67,8 @@ def cache_key(env) | |||
url.query = params.any? ? build_query(params) : nil | |||
end | |||
url.normalize! | |||
url.request_uri | |||
|
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.
There appears to be a trailing whitespace here according to Travis:
lib/faraday_middleware/response/caching.rb:70 Line contains trailing whitespace
@timrogers just touching base to know if you might have some time to close this off? It's basically finished except for that small typo 👍 |
Yes - sure. I’ll do this shortly.
|
Issue lostisland#132 notes that the caching middleware can generate keys which are too long when the input is a complex URL, leading to errors like `Errno::ENAMETOOLONG: File name too long @ rb_sysopen`. (The effective length limit depends on what cache driver you're using.) At the moment, we use the normalised request URI as the cache key. The fixes the issue by using `Digest::SHA1.hexdigest` to hash the URLs, giving us a constant 20-byte result. The trade-off of using a hash is that: * there is the potential for collisions (as rare as they will realistically be!) * performing a hash takes time
da6ba29
to
8922555
Compare
Thanks @timrogers! |
Issue #132 notes that the caching middleware can generate keys which are too long when the input is a complex URL, leading to errors like
Errno::ENAMETOOLONG: File name too long @ rb_sysopen
. (The effective length limit depends on what cache driver you're using.)At the moment, we use the normalised request URI as the cache key. The fixes the issue by using
Digest::SHA1.hexdigest
to hash the URLs, giving us a constant 20-byte result.The trade-off of using a hash is that: