From ccaf6fd941e86ea08197b787864bec4a01f658e0 Mon Sep 17 00:00:00 2001 From: Marcell Ferenc Date: Mon, 5 Aug 2024 11:57:46 +0200 Subject: [PATCH] Switch DefaultHasher to xxh128 for a faster alternative to MD5. (#478) * Switch DefaultHasher to xxh128 for a faster alternative to MD5. - See https://xxhash.com/ - Laravel is considering replacing MD5 with xxh128: https://github.com/laravel/framework/pull/52301 * Update ResponseHasherTest to reflect xxh128 algorithm changes --- src/Hasher/DefaultHasher.php | 3 ++- tests/ResponseHasherTest.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Hasher/DefaultHasher.php b/src/Hasher/DefaultHasher.php index edf8c52..a2a47b5 100644 --- a/src/Hasher/DefaultHasher.php +++ b/src/Hasher/DefaultHasher.php @@ -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" ); } diff --git a/tests/ResponseHasherTest.php b/tests/ResponseHasherTest.php index 03eae2e..aaf05dd 100644 --- a/tests/ResponseHasherTest.php +++ b/tests/ResponseHasherTest.php @@ -20,7 +20,7 @@ $this->cacheProfile->shouldReceive('useCacheNameSuffix')->andReturn('cacheProfileSuffix'); assertEquals( - 'responsecache-467d6e9cb7425ed9d3e114e44eb7117f', + 'responsecache-9937bec32aa1918917ad64b2b25f2982', $this->requestHasher->getHashFor($this->request) ); });