A stable lowercase-hex hash. cachem keys may contain only lowercase
letters and numbers, so a URL cannot be one directly and the inputs are
hashed instead. rlang::hash() returns lowercase hex, which satisfies the
rule.
Details
The salt and the schema version are inside the hash, so changing either
yields a fresh keyspace. Set BIOHTTP_CACHE_SALT per deployment: a shared
disk cache would otherwise collide across app versions, and it would leak
which queries were run to anyone able to probe it.
Put anything that changes the answer into params, credentials
included. The wrappers pass their headers through, because two callers
hitting the same URL with different tokens can legitimately get different
responses, and keying on the URL alone would serve one caller's data to the
other. The cost is that rotating a token misses the cache once, which is the
right trade.
Examples
cache_key("gnomAD", "GET https://example.org/v1/gene/BRCA1")
#> [1] "c78efd8b2316b27f48b66212054e32cd"
cache_key("gnomAD", "POST https://example.org/graphql", list(q = "BRCA1"))
#> [1] "572c652c8a78fbd9e901acfb4b49c691"