# @jest/create-cache-key-function

> This module creates a function which is used for generating cache keys used by code transformers in Jest.

Latest version **30.5.1** (published 2026-09-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jest/create-cache-key-function
pnpm add @jest/create-cache-key-function
yarn add @jest/create-cache-key-function
bun add @jest/create-cache-key-function
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; popular repo.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 30.5.1 |
| Published | 2026-09-01 |
| First published | 2020-10-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^18.14.0 \|\| ^20.0.0 \|\| ^22.0.0 \|\| >=24.0.0 |
| Dependencies | 1 |
| Unpacked size | 8.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 45458 |
| Maintainers | aaronabramov, simenb, rickhanlonii, openjs-operations, cpojer |

## Links

- npm: https://www.npmjs.com/package/@jest/create-cache-key-function
- Repository: https://github.com/jestjs/jest
- Homepage: https://github.com/jestjs/jest#readme
- Issues: https://github.com/jestjs/jest/issues
- npm.io page: https://npm.io/package/@jest/create-cache-key-function

## Dependencies (1)

- [@jest/types](https://npm.io/package/@jest/types.md) 30.5.1

## Recent versions

- 30.5.1 (latest) — 2026-09-01
- 30.0.0-rc.1 (next) — 2025-06-09
- 30.5.0 — 2026-08-28
- 30.4.1 — 2026-05-08
- 30.4.0 — 2026-05-07
- 30.3.0 — 2026-03-10
- 30.2.0 — 2025-09-28
- 30.0.5 — 2025-07-22
- 30.0.2 — 2025-06-19
- 30.0.1 — 2025-06-18
- 30.0.0 — 2025-06-10
- 30.0.0-beta.8 — 2025-06-04
- 30.0.0-beta.7 — 2025-06-04
- 30.0.0-beta.6 — 2025-06-03
- 30.0.0-beta.3 — 2025-05-27
- … 74 more at https://npm.io/package/@jest/create-cache-key-function/versions

## README

# jest-create-cache-key-function

This module creates a function which is used for generating cache keys used by code transformers in Jest.

## Install

```sh
$ npm install --save-dev @jest/create-cache-key-function
```

## API

### `createCacheKey(files?: Array<string>, values?: Array<String>, length?: number): GetCacheKeyFunction`

Returns a function that can be used to generate cache keys based on source code of provided files and provided values.

#### Parameters

- `files`: [Optional] Array of absolute paths to files whose code should be accounted for when generating cache key
- `values`: [Optional] Array of string values that should be accounted for when generating cache key
- `length`: [Optional] Length of the resulting key. The default is `32`, or `16` on Windows.

**Note:**

The source code for your test is already taken into account when generating the cache key. The `files` array should be used to provide files that are not directly related to your code such as external configuration files.

## Usage

Here is some sample usage code while creating a new transformer for Jest

```javascript
const createCacheKeyFunction =
  require('@jest/create-cache-key-function').default;

const filesToAccountFor = [
  __filename,
  require.resolve('some-package-name/package.json'),
];

const valuesToAccountFor = [process.env.SOME_LOCAL_ENV, 'Some_Other_Value'];

module.exports = {
  process(src, filename, config, options) {},
  getCacheKey: createCacheKeyFunction(filesToAccountFor, valuesToAccountFor),
};
```

---
_Source: https://npm.io/package/@jest/create-cache-key-function · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
