-
Notifications
You must be signed in to change notification settings - Fork 16
Added CacheKeyGenerator #35
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
Also added a default generator
Im done with this PR now. It is ready for review. PS: The commit "Support PSR-4" was a typo. I ment to write "Support PHP 5.4" |
@@ -338,12 +342,14 @@ private function configureOptions(OptionsResolver $resolver) | |||
'hash_algo' => 'sha1', | |||
'methods' => ['GET', 'HEAD'], | |||
'respect_response_cache_directives' => ['no-cache', 'private', 'max-age', 'no-store'], | |||
'cache_key_generator' => null, |
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.
Not sure if I should use null here or if I should instanciate the default generator. Using null will make sure we do not instanceiate unneeded objects.
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.
I had a few small comments, but looks ok. My fear is that we are putting too much logic here. Do you think the caching logic could be used elsewhere too? If so, should we extract it and move it to message for example?
src/CachePlugin.php
Outdated
$body = (string) $request->getBody(); | ||
if (!empty($body)) { | ||
$body = ' '.$body; | ||
if (null === $this->config['cache_key_generator']) { |
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.
I would move this check right after the option resolution. I don't see any benefit in timing here, this will be resolved sooner or later.
* | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class RequestLineAndBodyGenerator implements CacheKeyGenerator |
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.
Can we find a shorter name for this?
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.
Yes please! Any suggestions?
spec/CachePluginSpec.php
Outdated
@@ -2,6 +2,7 @@ | |||
|
|||
namespace spec\Http\Client\Common\Plugin; | |||
|
|||
use Http\Client\Common\Plugin\Generator\RequestLineAndBodyGenerator; |
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.
Hm, maybe put this under ...\Plugin\Cache\...
Thank you for the feedback. I've updated. I renamed the generator to "SimpleGenerator" since it uses an naive approach.
The Im not sure it make sense to try to reuse the cache logic. Not at this point, because the code it too coupled to this specific use case. But I will not close that door forever. If I recall correctly we decided to not have cache logic in message because we did not want to have so many external dependencies in php-http/message. But you may be referring to the HTTP specific parts... Again, not sure. I think we can let this library grow and mature. It is an implementation (and not an abstraction like most of our other libraries) so it is fine to bump it to 2.x and 3.x when we see a need for it. |
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.
i like this and think its fine to put in here at least for now. lets improve the cache plugin and if we realize we need the cache key elsewhere we can always push it upstream in a BC way as the cache depends on client-common
Thank you for the reviews. |
please add documentation for this. i created php-http/documentation#187 so we don't forget. |
Thank you |
Introducing CacheKeyGenerator interface. This will make sure one can control how a cache key is generated.
This will fix #30