Files
web/packages/common/dataCache/DistributedCache/generateCacheKey/index.ts
Anton Gunnarsson 048a477e52 Merged in feat/common-package (pull request #2333)
feat: Add common package

* Add isEdge, safeTry and dataCache to new common package

* Add eslint and move prettier config

* Fix yarn lock

* Clean up tests

* Add lint-staged config to common

* Add missing dependencies


Approved-by: Joakim Jäderberg
2025-06-11 13:08:39 +00:00

23 lines
561 B
TypeScript

import { getPrefix } from "./getPrefix"
export function generateCacheKey(
key: string | string[],
options?: { includeGitHashInKey?: boolean }
): string {
const includeGitHashInKey = options?.includeGitHashInKey ?? true
const keyArray = (Array.isArray(key) ? key : [key]).filter(Boolean)
if (keyArray.length === 0) {
throw new Error("No keys provided")
}
const prefix = getPrefix({
includeGitHashInKey,
includeBranchPrefix: true,
})
const keyTokens = [prefix, keyArray.join("_")].filter(Boolean).join(":")
return keyTokens
}