---
url: /api/symbols/workbox-swkit/expiration/cacheexpiration.md
---

# CacheExpiration

Class @vite-pwa/workbox-swkit/expiration

The `CacheExpiration` class allows you define an expiration and / or
limit on the number of responses stored in a
[`Cache`](https://developer.mozilla.org/en-US/docs/Web/API/Cache).

## Constructor

```ts
new CacheExpiration(cacheName: string, config: CacheExpirationConfig)
```

To construct a new CacheExpiration instance you must provide at least
one of the `config` properties.

**Parameters**

* `cacheName` – Name of the cache to apply restrictions to.

## Methods

### delete()

```ts
delete(): Promise<void>
```

Removes the IndexedDB object store used to keep track of cache expiration
metadata.

### expireEntries()

```ts
expireEntries(): Promise<void>
```

Expires entries for the given cache and given criteria.

### isURLExpired()

```ts
isURLExpired(url: string): Promise<boolean>
```

Can be used to check if a URL has expired or not before it's used.

This requires a look up from IndexedDB, so can be slow.

Note: This method will not remove the cached entry, call
`expireEntries()` to remove indexedDB and Cache entries.

**Returns:**

### updateTimestamp()

```ts
updateTimestamp(url: string): Promise<void>
```

Update the timestamp for the given URL. This ensures the when
removing entries based on maximum entries, most recently used
is accurate or when expiring, the timestamp is up-to-date.
