generateKey
generateKey(
args):string
Defined in: core/src/utils/helper.ts:58
Serialise call arguments into the query-key segment that identifies them.
Equal Candid values must give equal keys, and different values different
ones, which plain JSON.stringify does not ensure:
- Record fields are unordered in Candid, and TanStack Query hashes object
keys order-independently, so plain objects are written with their keys
sorted. Otherwise
{ owner, subaccount }and{ subaccount, owner }— the same record, the same bytes on the wire — got separate cache entries, andgetQueryData/invalidateQueriesspelled one way missed the other. - JSON writes NaN, Infinity and -Infinity all as
null, and -0 as0, so a query for one float was answered from another’s cache entry. They are written as"\u0000NaN","\u0000Infinity","\u0000-Infinity"and"\u0000-0", and a string that starts with U+0000 gets one more in front, so no string argument can produce that tag. It has to be unforgeable: this function is public and an infinite query’sgetKeyArgsmay return any value, so a bare"Infinity"would let[Infinity]and["Infinity"]share a cache entry. - A blob given as a
Uint8Array, a byte array or (to a DisplayReactor) hex text sends the same bytes in every form.Reactor.generateQueryKeyhands each blob of the method’s arguments over as aBlobKey, written here as"\u0000blob:"and its lowercase hex. It carries the same tag, so no argument can produce it: not hex text given to a Reactor, which refuses it, and not a BigInt, whose digits are also hex. - A value the reactor refuses can have the JSON of one it takes:
undefinedis written asnullin an array, and a BigInt as its digits. The key hands such a value over as aRefusedKey, written here as"\u0000refused:"and the key of the value alone, behind the same tag.
BigInts are written as decimal strings. Everything else — including every string that does not start with U+0000, and an object whose keys are already in sorted order — serialises exactly as before.
Parameters
Section titled “Parameters”any[]
Returns
Section titled “Returns”string