Skip to content

Use sha1 to reduce the risk of collisions #12

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 7 commits into from
Aug 2, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Support setting a hash_algo
  • Loading branch information
GrahamCampbell authored Aug 1, 2016
commit 5094fef214d3610e2bd4c7c9bd72e4dea6d6a3bf
5 changes: 4 additions & 1 deletion src/CachePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ final class CachePlugin implements Plugin
*
* @var bool $respect_cache_headers Whether to look at the cache directives or ignore them
* @var int $default_ttl If we do not respect cache headers or can't calculate a good ttl, use this value.
* @var string $hash_algo The hashing algorithm to use when generating cache keys.
* }
*/
public function __construct(CacheItemPoolInterface $pool, StreamFactory $streamFactory, array $config = [])
Expand Down Expand Up @@ -150,7 +151,7 @@ private function getCacheControlDirective(ResponseInterface $response, $name)
*/
private function createCacheKey(RequestInterface $request)
{
return sha1($request->getMethod().' '.$request->getUri());
return hash($this->config['hash_algo'], $request->getMethod().' '.$request->getUri());
}

/**
Expand Down Expand Up @@ -196,9 +197,11 @@ private function configureOptions(OptionsResolver $resolver)
$resolver->setDefaults([
'default_ttl' => null,
'respect_cache_headers' => true,
'hash_algo' => 'sha1',
]);

$resolver->setAllowedTypes('default_ttl', ['int', 'null']);
$resolver->setAllowedTypes('respect_cache_headers', 'bool');
$resolver->setAllowedValues('hash_algo', hash_algos());
}
}