diff --git a/docs/src/config.md b/docs/src/config.md index 710506e..06a0d4a 100644 --- a/docs/src/config.md +++ b/docs/src/config.md @@ -50,18 +50,14 @@ The `generateKey` property defines the function responsible for generating uniqu By default, it employs a strategy that prioritizes the `id` if available, falling back to a string generated using various request properties. The default implementation generates a 32-bit hash key using the `method`, `baseURL`, `params`, `data`, and `url` of the request. -While this default implementation offers reasonable uniqueness for most scenarios, it's worth noting that there's a [theoretical 50% probability of collisions after approximately 77,000 keys](https://preshing.com/20110504/hash-collision-probabilities/) have been generated. - -However, this limitation is typically inconsequential in browser environments due to their 5MB storage limit, which is reached long before the collision threshold. - ::: warning -In any persistent cache scenario where hitting over 77K unique keys is a possibility, it's advisable to use a more robust hashing algorithm to mitigate collision risks. For such cases, consider implementing a custom key generator function using libraries like [`object-hash`](https://www.npmjs.com/package/object-hash) for generating hash keys with significantly lower collision probabilities. +In any persistent cache scenario where hitting over 77K unique keys is a possibility, you should use a more robust hashing algorithm. + +[Read more](./guide/request-id.md#custom-generator) ::: -[Learn more about request ids.](./guide/request-id.md#custom-generator) - ## waiting diff --git a/docs/src/guide/request-id.md b/docs/src/guide/request-id.md index 5fc4577..0b61ebd 100644 --- a/docs/src/guide/request-id.md +++ b/docs/src/guide/request-id.md @@ -47,13 +47,20 @@ any possible differences between them and share the same cache for both. ## Custom Generator -If the default generator is not enough for your use case, you can provide your own custom -generator with the `generateKey` option. - -By default, it extracts `method`, `baseURL`, `query`, `params`, `data` and `url` +By default, the id generator extracts `method`, `baseURL`, `query`, `params`, `data` and `url` properties from the request object and hashes it into a number with [`object-code`](https://www.npmjs.com/package/object-code). +While this default implementation offers reasonable uniqueness for most scenarios, it's worth noting that there's a [theoretical 50% probability of collisions after approximately 77,000 keys](https://preshing.com/20110504/hash-collision-probabilities/) have been generated. + +However, this limitation is typically inconsequential in browser environments due to their 5MB storage limit, which is reached long before the collision threshold. + +::: warning + +Consider implementing a custom key generator function using libraries like [`object-hash`](https://www.npmjs.com/package/object-hash) for generating hash keys with significantly lower collision probabilities when hitting over 77K unique keys is a possibility + +::: + Here's an example of a generator that only uses the `url` and `method` and `custom` properties: