mcollina / async-cache-dedupe

Async cache with dedupe support
MIT License
640 stars 40 forks source link

Add an option to use JSON.stringify for the hashing #11

Closed codeflyer closed 2 years ago

codeflyer commented 2 years ago

As mentioned here: https://github.com/mcollina/async-cache-dedupe/issues/8

the safe-stable-stringify is a bottleneck in the key generation.

The safe-stable option is not always required. When the source of the keys is well know the developer can choose to use the JSON.stringify function instead of having a safe one.

A GQL server, for examples, does the request always in the same way and a lot of cache parameters are often very simple

eg.

{"id": "abc"}

Using the non-safe version can cause more values in the cache but some times the result is better than having an over optimised cache.

mcollina commented 2 years ago

This is not needed. It's already possible to use whatever algorithm we want for this by using the serialize option.

Changing https://github.com/mercurius-js/cache/blob/ba55f7b4a56bbdcd2f1081bac8e9acae20a3dd4b/index.js#L111

to return JSON.stringify({ self, arg, fields, extendKey })