Skip to content

Commit

Permalink
Switch DefaultHasher to xxh128 for a faster alternative to MD5. (#478)
Browse files Browse the repository at this point in the history
* Switch DefaultHasher to xxh128 for a faster alternative to MD5.

- See https://xxhash.com/
- Laravel is considering replacing MD5 with xxh128: laravel/framework#52301

* Update ResponseHasherTest to reflect xxh128 algorithm changes
  • Loading branch information
marcell-ferenc authored Aug 5, 2024
1 parent d4cf7ec commit ccaf6fd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Hasher/DefaultHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public function getHashFor(Request $request): string
{
$cacheNameSuffix = $this->getCacheNameSuffix($request);

return 'responsecache-' . md5(
return 'responsecache-' . hash(
'xxh128',
"{$request->getHost()}-{$this->getNormalizedRequestUri($request)}-{$request->getMethod()}/$cacheNameSuffix"
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ResponseHasherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
$this->cacheProfile->shouldReceive('useCacheNameSuffix')->andReturn('cacheProfileSuffix');

assertEquals(
'responsecache-467d6e9cb7425ed9d3e114e44eb7117f',
'responsecache-9937bec32aa1918917ad64b2b25f2982',
$this->requestHasher->getHashFor($this->request)
);
});
Expand Down

0 comments on commit ccaf6fd

Please sign in to comment.