# Caches

Open your agent in the console and select **Functions**, then open the **Caches** tab.

This page documents the Caches tab. Related pages:

- [Functions](3-functions.md)
- [JSON Web Tokens](3.1-json-web-tokens.md)

## What a cache does

A cache stores a structured value for a fixed amount of time.

Caches are used for two main purposes:

- store Function results for reuse
- store tokens generated by a JSON Web Token configuration

## Caches tab

The tab shows a table with these columns:

- `Name`
- `Description`
- `Cache ID`
- `TTL`

Available actions:

- `Create`
- `Value`
- `Edit`
- `Delete`

## Create or edit a cache

Select **Create** or **Edit** to open the cache modal.

### Name

Use a short, descriptive name.

Recommended style:

- lowercase
- underscores between words

Examples:

- `order_status_cache`
- `acme_api_jwt`
- `crm_lookup_cache`

### Description

Description is required.

Use it to explain exactly what the cache is for. Keep it clear enough that an operator can tell it apart from other caches at a glance.

Good examples:

- `Most recent order status lookup result`
- `Bearer token for Acme service requests`
- `Latest CRM contact lookup result`

### TTL

TTL is the cache lifetime in seconds.

Use shorter TTLs when the value changes frequently. Use longer TTLs when the value is expensive to regenerate and can safely be reused.

## View a cache value

Select **Value** to open the current cache contents in a read-only viewer.

If the cache does not currently contain a value, the viewer shows an empty state.

The UI does not provide a direct way to edit a cache value manually.

## How caches work with Functions

When you select a cache in a Function:

1. Leilani checks that cache before running the Function.
2. If the cache has a current value, Leilani can return that value instead of running the Function again.
3. If the cache is empty or expired, the Function runs normally.
4. The new result is stored in the cache.

This is useful for:

- repeated lookups
- integrations with expensive or rate-limited backends
- data the agent may need again during later calls

If a Function uses **Hide function output**, the result can still be stored in the cache.

## How caches work with JSON Web Tokens

Each JSON Web Token writes its signed token into a selected cache.

That means:

- the cache TTL controls the token lifetime
- Functions can rely on that cache when they need a current token

Use a dedicated cache for each token.

## Cache design rules

Use one cache per purpose.

Do not reuse the same cache for unrelated data.

In particular:

- do not use a JWT cache as a Function result cache
- do not use one cache for several unrelated integrations

## Operator guidance

- Name caches by purpose, not by implementation detail.
- Write descriptions that make the intended use obvious.
- Use a separate cache for credentials and a separate cache for Function results.
- Choose TTL values that match the freshness requirements of the integration.

## Limitations and notes

- Cache values are view-only in the current UI.
- Cache IDs are shown in the table so you can identify the exact cache when reviewing configurations.
