---
title: CacheEntry
summary: Represents a cached item retrieved via CoreCache.lookup or as part of a TransactionCacheEntry.insertAndStreamBack operation.
url: https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/cache/class.CacheEntry/
---

**Kind:** Class  
**Module:** [cache](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/cache/)  
**Package:** @fastly/js-compute 4.0.1  
**Since:** 3.9.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/cache.d.ts#L392

Represents a cached item retrieved via [CoreCache.lookup](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/cache/class.CoreCache/#method-lookup) or as part of a
[TransactionCacheEntry.insertAndStreamBack](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/cache/class.TransactionCacheEntry/#method-insertAndStreamBack) operation.

## Methods

### age

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/cache.d.ts#L437

```javascript
age(): number
```

The current age in milliseconds of the cached item.

**Returns**

`number`

### body

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/cache.d.ts#L415

```javascript
body(options?: CacheBodyOptions): ReadableStream
```

Retrieves the cached item as a `ReadableStream`.

Only one stream can be active at a time for a given `CacheEntry`. An error will be thrown if a stream is already active for this CacheEntry.

**Parameters**

- `options`: `CacheBodyOptions` (optional) — Optional property used to request a range of bytes within the cached item.

**Returns**

`ReadableStream`

### close

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/cache.d.ts#L396

```javascript
close(): void
```

Closes the connection to the cache for this `CacheEntry`.

**Returns**

`void`

### hits

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/cache.d.ts#L444

```javascript
hits(): number
```

Determines the number of cache hits to this cached item.

Note: this hit count only reflects the view of the server that supplied the cached item. Due to clustering, this count may vary between potentially many servers within the data center where the item is cached. See the [clustering documentation](https://developer.fastly.com/learning/vcl/clustering/) for details, though note that the exact caching architecture of Compute is different from VCL services.

**Returns**

`number`

### length

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/cache.d.ts#L422

```javascript
length(): number | null
```

The size in bytes of the cached item, if known.

**Returns**

`number | null`

The length in bytes, or `null` if the length is currently unknown. The length may be unknown if the item is currently being streamed into the cache without a fixed length.

### maxAge

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/cache.d.ts#L427

```javascript
maxAge(): number
```

The time in milliseconds for which the cached item is considered fresh.

**Returns**

`number`

### staleWhileRevalidate

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/cache.d.ts#L432

```javascript
staleWhileRevalidate(): number
```

The time in milliseconds for which a cached item can safely be used despite being considered stale.

**Returns**

`number`

### state

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/cache.d.ts#L401

```javascript
state(): CacheState
```

Returns a `CacheState` instance which reflects the current state of this `CacheEntry` instance.

**Returns**

`CacheState`

### userMetadata

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/cache.d.ts#L406

```javascript
userMetadata(): ArrayBuffer
```

The user-controlled metadata associated with the cached item.

**Returns**

`ArrayBuffer`
