---
title: "cache-rules set"
description: "Update cache rule for a query"
canonical: "https://pgbeam.com/docs/cli/projects/cache-rules/set"
last-updated: "2026-10-30T03:14:55.000Z"
---

# cache-rules set

> Update cache rule for a query

URL: https://pgbeam.com/docs/cli/projects/cache-rules/set

{/* Auto-generated from CLI commands. Do not edit. Run `pnpm generate:cli-docs` to regenerate. */}

Enable or disable caching for a specific query shape, identified by its xxhash64 hash. You can optionally override the TTL (time-to-live) and SWR (stale-while-revalidate) durations. Omitting `--ttl` or `--swr` uses the project-level defaults. Use `pgbeam cache-rules list` to find query hashes.

## Usage

```bash
pgbeam cache-rules set <query-hash> [flags]
```

## Options

| Option                  | Description                                                                                     | Required | Default |
| ----------------------- | ----------------------------------------------------------------------------------------------- | -------- | ------- |
| `<query-hash>`          | Query hash (xxhash64 hex) identifying the query shape. Find this via `pgbeam cache-rules list`. | Yes      | -       |
| `--database-id <value>` | ID of the database that owns the query                                                          | Yes      | -       |
| `--enabled <value>`     | Whether to enable caching for this query: "true" or "false"                                     | Yes      | -       |
| `--ttl <value>`         | TTL (time-to-live) override in seconds. Omit to use the project default.                        | No       | -       |
| `--swr <value>`         | SWR (stale-while-revalidate) override in seconds. Omit to use the project default.              | No       | -       |

> **Global options**
>
> All [global options](/docs/cli/global-options) (`--token`, `--profile`,
> `--project`, `--org`, `--json`, `--no-color`, `--no-trunc`, `--debug`) are
> also available on this command.

## Examples

```bash
# Enable caching for a query
pgbeam cache-rules set a1b2c3d4 --database-id db_xxx --enabled true

# Enable with custom TTL and SWR
pgbeam cache-rules set a1b2c3d4 --database-id db_xxx --enabled true --ttl 60 --swr 10

# Disable caching for a query
pgbeam cache-rules set a1b2c3d4 --database-id db_xxx --enabled false
```

## Output

Prints the updated cache rule showing whether caching is enabled, the TTL, and the SWR duration. With `--json`, returns the full cache rule entry.