---
title: "Cannot call `cacheLife()` outside `use cache`"
url: "https://nextjs.org/docs/messages/cache-life-outside-use-cache"
docs_index: /docs/llms.txt
---



## Why This Error Occurred

The `cacheLife()` function configures the `stale`, `revalidate`, and `expire` times for a cache entry. Call it from a function or component that uses the `use cache` or `use cache: private` directive. When you call `cacheLife()` outside a cached function, there is no cache entry to configure.

```jsx filename="app/page.js" highlight={4}
import { cacheLife } from 'next/cache'

export default async function Page() {
  cacheLife('hours') // No cache entry to configure
  return <p>...</p>
}
```

## Possible Ways to Fix It

Move `cacheLife()` inside the cached function whose lifetime you want to set.

```jsx filename="app/page.js" highlight={5}
import { cacheLife } from 'next/cache'

async function getProducts() {
  'use cache'
  cacheLife('hours') // Configures this cache entry
  return db.products.findMany()
}

export default async function Page() {
  const products = await getProducts()
  return <p>...</p>
}
```

If you don't intend to cache the function or component, remove the `cacheLife()` call.

## Useful Links

- [`cacheLife()` function](/docs/app/api-reference/functions/cacheLife)
- [`cacheTag()` function](/docs/app/api-reference/functions/cacheTag)
- [`use cache` directive](/docs/app/api-reference/directives/use-cache)
- [`use cache: private` directive](/docs/app/api-reference/directives/use-cache-private)
