---
title: "@vltpkg/registry-client: cache-entry — vlt docs"
description: "Documentation for the vlt client and the vlt registry."
url: "https://docs.vlt.io/client/api-reference/registry-client/cache-entry"
image: "https://docs.vlt.io/og/client/api-reference/registry-client/cache-entry"
lang: "en"
---

# cache-entry

## Classes

### CacheEntry

Defined in: src/registry-client/src/cache-entry.ts:145

#### Constructors

##### new CacheEntry()

```ts
new CacheEntry(
   statusCode, 
   headers, 
   __namedParameters): CacheEntry
```

Defined in: src/registry-client/src/cache-entry.ts:168

###### Parameters

| Parameter           | Type                                                                                                             |
| ------------------- | ---------------------------------------------------------------------------------------------------------------- |
| `statusCode`        | `number`                                                                                                         |
| `headers`           | `Uint8Array`<`ArrayBufferLike`>\[]                                                                               |
| `__namedParameters` | [`CacheEntryOptions`](https://docs.vlt.io/client/api-reference/registry-client/cache-entry.md#cacheentryoptions) |

###### Returns

[`CacheEntry`](https://docs.vlt.io/client/api-reference/registry-client/cache-entry.md#cacheentry)

#### Accessors

##### \_body

###### Get Signature

```ts
get _body(): Uint8Array
```

Defined in: src/registry-client/src/cache-entry.ts:397

Returns the body as a single Uint8Array, concatenating parts if needed.

###### Returns

`Uint8Array`

##### body

###### Get Signature

```ts
get body(): Uint8Array<ArrayBufferLike> | Record<string, any>
```

Defined in: src/registry-client/src/cache-entry.ts:583

###### Returns

`Uint8Array`<`ArrayBufferLike`> | `Record`<`string`, `any`>

##### cacheControl

###### Get Signature

```ts
get cacheControl(): CacheControl
```

Defined in: src/registry-client/src/cache-entry.ts:283

###### Returns

`CacheControl`

##### contentType

###### Get Signature

```ts
get contentType(): string
```

Defined in: src/registry-client/src/cache-entry.ts:306

###### Returns

`string`

##### date

###### Get Signature

```ts
get date(): undefined | Date
```

Defined in: src/registry-client/src/cache-entry.ts:264

###### Returns

`undefined` | `Date`

##### digest

###### Get Signature

```ts
get digest(): undefined | `sha512-${string}`
```

Defined in: src/registry-client/src/cache-entry.ts:516

The sha-512 member of an RFC 9530 `Repr-Digest` (or `Content-Digest`) response header, as an SRI string. A registry that serves packuments without `dist.integrity` labels each tarball this way instead.

###### Returns

`undefined` | `` `sha512-${string}` ``

##### fromCache

###### Get Signature

```ts
get fromCache(): boolean
```

Defined in: src/registry-client/src/cache-entry.ts:361

True when this entry was decoded from the on-disk cache.

###### Returns

`boolean`

##### headers

###### Get Signature

```ts
get headers(): Uint8Array<ArrayBufferLike>[]
```

Defined in: src/registry-client/src/cache-entry.ts:390

###### Returns

`Uint8Array`<`ArrayBufferLike`>\[]

##### headSize

###### Get Signature

```ts
get headSize(): undefined | number
```

Defined in: src/registry-client/src/cache-entry.ts:369

Byte length of the encoded head (4-byte length prefix + status + headers). Set when decoded from cache or after `encodeHead()`.

###### Returns

`undefined` | `number`

##### integrity

###### Get Signature

```ts
get integrity(): undefined | `sha512-${string}`
```

Defined in: src/registry-client/src/cache-entry.ts:507

###### Returns

`undefined` | `` `sha512-${string}` ``

###### Set Signature

```ts
set integrity(i): void
```

Defined in: src/registry-client/src/cache-entry.ts:501

###### Parameters

| Parameter | Type                                    |
| --------- | --------------------------------------- |
| `i`       | `undefined` \| `` `sha512-${string}` `` |

###### Returns

`void`

##### integrityActual

###### Get Signature

```ts
get integrityActual(): `sha512-${string}`
```

Defined in: src/registry-client/src/cache-entry.ts:489

###### Returns

`` `sha512-${string}` ``

###### Set Signature

```ts
set integrityActual(i): void
```

Defined in: src/registry-client/src/cache-entry.ts:496

###### Parameters

| Parameter | Type                     |
| --------- | ------------------------ |
| `i`       | `` `sha512-${string}` `` |

###### Returns

`void`

##### isGzip

###### Get Signature

```ts
get isGzip(): boolean
```

Defined in: src/registry-client/src/cache-entry.ts:649

###### Returns

`boolean`

##### isJSON

###### Get Signature

```ts
get isJSON(): boolean
```

Defined in: src/registry-client/src/cache-entry.ts:588

###### Returns

`boolean`

##### maxAge

###### Get Signature

```ts
get maxAge(): number
```

Defined in: src/registry-client/src/cache-entry.ts:272

###### Returns

`number`

##### ok

###### Get Signature

```ts
get ok(): boolean
```

Defined in: src/registry-client/src/cache-entry.ts:387

True when the registry answered with a 2xx.

`RegistryClient.request()` resolves for every status, so this is how code holding a real CacheEntry asks "did it work?".

Note this is the strict form. Use it only where a genuine CacheEntry is guaranteed; `assertOk` uses the loose range check because it is also handed duck-typed responses.

###### Returns

`boolean`

##### staleWhileRevalidate

###### Get Signature

```ts
get staleWhileRevalidate(): boolean
```

Defined in: src/registry-client/src/cache-entry.ts:291

###### Returns

`boolean`

##### statusCode

###### Get Signature

```ts
get statusCode(): number
```

Defined in: src/registry-client/src/cache-entry.ts:373

###### Returns

`number`

##### valid

###### Get Signature

```ts
get valid(): boolean
```

Defined in: src/registry-client/src/cache-entry.ts:318

###### Returns

`boolean`

#### Methods

##### \[kCustomInspect]\()

```ts
kCustomInspect: string
```

Defined in: src/registry-client/src/cache-entry.ts:255

###### Parameters

| Parameter | Type             |
| --------- | ---------------- |
| `depth`   | `number`         |
| `options` | `InspectOptions` |

###### Returns

`string`

##### addBody()

```ts
addBody(b): void
```

Defined in: src/registry-client/src/cache-entry.ts:346

Add contents to the entry body.

###### Parameters

| Parameter | Type         |
| --------- | ------------ |
| `b`       | `Uint8Array` |

###### Returns

`void`

##### buffer()

```ts
buffer(): Buffer
```

Defined in: src/registry-client/src/cache-entry.ts:573

Return the body of the entry as a Buffer

###### Returns

`Buffer`

##### checkDigest()

```ts
checkDigest(required, context): `sha512-${string}`
```

Defined in: src/registry-client/src/cache-entry.ts:452

Check the body against the RFC 9530 digest the server sent with it, for a response that had no expected integrity. A registry that omits `dist.integrity` labels every tarball, so a missing digest fails when `required`. Like [checkIntegrity](https://docs.vlt.io/client/api-reference/registry-client/cache-entry.md#checkintegrity), only for an actual http response: cached bodies are un-gzipped in place.

**Will throw** on a mismatch. Returns the hash of the body.

###### Parameters

| Parameter  | Type                                                                                                       |
| ---------- | ---------------------------------------------------------------------------------------------------------- |
| `required` | `boolean`                                                                                                  |
| `context`  | [`ErrorCauseOptions`](https://docs.vlt.io/client/api-reference/error-cause/reference.md#errorcauseoptions) |

###### Returns

`` `sha512-${string}` ``

##### checkIntegrity()

```ts
checkIntegrity(context): this is CacheEntry & { integrity: `sha512-${string}` }
```

Defined in: src/registry-client/src/cache-entry.ts:427

Check that the sri integrity string that was provided to the ctor matches the body that we actually received. This should only be called AFTER the entire body has been completely downloaded.

This method **will throw** if the integrity values do not match.

Note that this will _usually_ not be true if the value is coming out of the cache, because cache entries not exploded into the global store are un-gzipped in place. It should _only_ be called for artifacts that come from an actual http response, whatever its encoding: an identity body is hashed as it came, a gzipped one before anything un-gzips it in memory.

Returns true if anything was actually verified.

###### Parameters

| Parameter | Type                                                                                                       |
| --------- | ---------------------------------------------------------------------------------------------------------- |
| `context` | [`ErrorCauseOptions`](https://docs.vlt.io/client/api-reference/error-cause/reference.md#errorcauseoptions) |

###### Returns

``this is CacheEntry & { integrity: `sha512-${string}` }``

##### deleteHeader()

```ts
deleteHeader(h): void
```

Defined in: src/registry-client/src/cache-entry.ts:559

Remove a header, if present

###### Parameters

| Parameter | Type     |
| --------- | -------- |
| `h`       | `string` |

###### Returns

`void`

##### encode()

```ts
encode(): Buffer
```

Defined in: src/registry-client/src/cache-entry.ts:896

Encode the entry as a single Buffer for writing to the cache

###### Returns

`Buffer`

##### encodeHead()

```ts
encodeHead(): Buffer
```

Defined in: src/registry-client/src/cache-entry.ts:861

Encode status + headers (no body) as they appear at the start of an on-disk cache file.

###### Returns

`Buffer`

##### getHeader()

```ts
getHeader(h): undefined | Uint8Array<ArrayBufferLike>
```

Defined in: src/registry-client/src/cache-entry.ts:528

Give it a key, and it'll return the buffer of that header value

###### Parameters

| Parameter | Type     |
| --------- | -------- |
| `h`       | `string` |

###### Returns

`undefined` | `Uint8Array`<`ArrayBufferLike`>

##### getHeaderString()

```ts
getHeaderString(h): undefined | string
```

Defined in: src/registry-client/src/cache-entry.ts:535

Give it a key, and it'll return the decoded string of that header value

###### Parameters

| Parameter | Type     |
| --------- | -------- |
| `h`       | `string` |

###### Returns

`undefined` | `string`

##### json()

```ts
json(): JSONObj
```

Defined in: src/registry-client/src/cache-entry.ts:727

Parse the entry body as JSON and return the result

###### Returns

[`JSONObj`](https://docs.vlt.io/client/api-reference/registry-client/cache-entry.md#jsonobj)

##### labelArtifact()

```ts
labelArtifact(): void
```

Defined in: src/registry-client/src/cache-entry.ts:635

Label a 200 network body that is not json and came with no content-type `application/octet-stream`, the way the json sniff labels json `text/json`.

The label says the hash the entry is stored under is the hash of its bytes as served, checked or recorded by `RegistryClient.request()`. So it is applied only where that is known, right before such an entry is stored, and never by the sniff: an entry with no content-type read back from the cache is not known to be one.

A decoded entry, an error body, an empty body, json, and a body served with a content-type are left as they are. Not an error body or an empty one: a content-type that is not json makes an entry immutable (see [valid](https://docs.vlt.io/client/api-reference/registry-client/cache-entry.md#valid)), which neither was when served with none, and no artifact is empty. The length is checked after the sniff, which un-gzips a body with no content-type.

###### Returns

`void`

##### setHeader()

```ts
setHeader(h, value): void
```

Defined in: src/registry-client/src/cache-entry.ts:545

Set a header to a specific value

###### Parameters

| Parameter | Type                                        |
| --------- | ------------------------------------------- |
| `h`       | `string`                                    |
| `value`   | `string` \| `Uint8Array`<`ArrayBufferLike`> |

###### Returns

`void`

##### text()

```ts
text(): string
```

Defined in: src/registry-client/src/cache-entry.ts:719

Return the body of the entry as utf8 text Automatically unzips if the content is gzip encoded

###### Returns

`string`

##### toJSON()

```ts
toJSON(): object
```

Defined in: src/registry-client/src/cache-entry.ts:215

###### Returns

`object`

##### unzip()

```ts
unzip(): boolean
```

Defined in: src/registry-client/src/cache-entry.ts:700

Un-gzip encode the body. Returns true if it was previously gzip (so something was done), otherwise returns false.

###### Returns

`boolean`

##### unzippedIntegrity()

```ts
unzippedIntegrity(): `sha512-${string}`
```

Defined in: src/registry-client/src/cache-entry.ts:485

The hash of the body un-gzipped, or of the body itself if it is not gzipped, without un-gzipping the entry. Bounded like [unzip](https://docs.vlt.io/client/api-reference/registry-client/cache-entry.md#unzip), and throws like it on a body that will not un-gzip.

Never the hash to record for an artifact, which is the hash of its bytes as served. It pins the same content, though, and is what a body hashed after something un-gzipped it was pinned with.

###### Returns

`` `sha512-${string}` ``

##### decode()

```ts
static decode(buffer, options): CacheEntry
```

Defined in: src/registry-client/src/cache-entry.ts:790

Pass the contents of a @vltpkg/cache.Cache object as a buffer, and this static method will decode it into a CacheEntry representing the cached response.

###### Parameters

| Parameter | Type                                                                                                             |
| --------- | ---------------------------------------------------------------------------------------------------------------- |
| `buffer`  | `Uint8Array`                                                                                                     |
| `options` | [`CacheEntryOptions`](https://docs.vlt.io/client/api-reference/registry-client/cache-entry.md#cacheentryoptions) |

###### Returns

[`CacheEntry`](https://docs.vlt.io/client/api-reference/registry-client/cache-entry.md#cacheentry)

##### decodeHead()

```ts
static decodeHead(buffer): CacheEntry
```

Defined in: src/registry-client/src/cache-entry.ts:772

Decode only the status/headers from an encoded cache buffer. The body is not read; `headSize` records how many bytes the head occupies so a later `encodeHead()` can be patched in place.

###### Parameters

| Parameter | Type         |
| --------- | ------------ |
| `buffer`  | `Uint8Array` |

###### Returns

[`CacheEntry`](https://docs.vlt.io/client/api-reference/registry-client/cache-entry.md#cacheentry)

##### isGzipEntry()

```ts
static isGzipEntry(buffer): boolean
```

Defined in: src/registry-client/src/cache-entry.ts:827

###### Parameters

| Parameter | Type         |
| --------- | ------------ |
| `buffer`  | `Uint8Array` |

###### Returns

`boolean`

##### isTarballEntry()

```ts
static isTarballEntry(buffer): boolean
```

Defined in: src/registry-client/src/cache-entry.ts:838

Head-only check for a 200 non-JSON body with an integrity header, i.e. a tarball the global store can be built from.

###### Parameters

| Parameter | Type         |
| --------- | ------------ |
| `buffer`  | `Uint8Array` |

###### Returns

`boolean`

##### tarballIntegrity()

```ts
static tarballIntegrity(buffer): undefined | `sha512-${string}`
```

Defined in: src/registry-client/src/cache-entry.ts:846

The hash recorded on such an entry, or undefined if this is not one. [isTarballEntry](https://docs.vlt.io/client/api-reference/registry-client/cache-entry.md#istarballentry) is built on this, and both only need the head.

###### Parameters

| Parameter | Type         |
| --------- | ------------ |
| `buffer`  | `Uint8Array` |

###### Returns

`undefined` | `` `sha512-${string}` ``

## Type Aliases

### CacheEntryOptions

```ts
type CacheEntryOptions = object;
```

Defined in: src/registry-client/src/cache-entry.ts:95

#### Type declaration

| Name                             | Type                                                                                   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| -------------------------------- | -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `body`?                          | `Uint8Array`                                                                           | An optional body to use. Adopted as-is (no copy). The caller must not mutate or reuse it. Used when decoding a cache entry from a buffer. Do not call `addBody` after providing this. Worker-thread transfers must copy or structuredClone first so the cache ArrayBuffer is not detached.                                                                                                                                                                                                                                                     |
| `contentLength`?                 | `number`                                                                               | An optional content length of the body to use, if undefined the content-length header will be used.                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `integrity`?                     | [`Integrity`](https://docs.vlt.io/client/api-reference/types/reference.md#integrity-2) | The expected integrity value for this response body                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `stale-while-revalidate-factor`? | `number`                                                                               | If the server does not serve a `stale-while-revalidate` value in the `cache-control` header, then this multiplier is applied to the `max-age` or `s-maxage` values. By default, this is `60`, so for example a response that is cacheable for 5 minutes will allow a stale response while revalidating for up to 5 hours. If the server _does_ provide a `stale-while-revalidate` value, then that is always used. Set to 0 to prevent any `stale-while-revalidate` behavior unless explicitly allowed by the server's `cache-control` header. |
| `trustIntegrity`?                | `boolean`                                                                              | Whether to trust the integrity, or calculate the actual value. This indicates that we just accept whatever the integrity is as the actual integrity for saving back to the cache, because it's coming directly from the registry that we fetched a packument from, and is an initial gzipped artifact request.                                                                                                                                                                                                                                 |

---

### JSONObj

```ts
type JSONObj = Record<string, JSONField>;
```

Defined in: src/registry-client/src/cache-entry.ts:36
