> For the complete documentation index, see [llms.txt](https://docs.lingoql.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lingoql.com/sub0/apis-abi/caching.md).

# Caching

Caching lets Sub0 reuse earlier results instead of recomputing them.

Use it for read-heavy endpoints, expensive queries, and third-party calls.

### Cache structure

```json
"cacheable": {
  "read_from_cache": true,
  "cache_key": "users_page_$PAYLOAD.page_number",
  "duration": 3600,
  "invalidate_cache_keys": ["$PAYLOAD.invalidate_cache_keys"]
}
```

What each field does:

* `read_from_cache` checks cache before running the action
* `cache_key` identifies the stored result
* `duration` sets the TTL in seconds
* `invalidate_cache_keys` removes related cache entries

### Cache a single actionable

```json
{
  "id": 2,
  "mode": "HTTPREQUEST",
  "http": {
    "url": "https://api.example.com/pricing",
    "method": "GET"
  },
  "cacheable": {
    "read_from_cache": true,
    "cache_key": "pricing_$PAYLOAD.page_number",
    "duration": 600
  }
}
```

### Cache a whole endpoint

```json
{
  "id": "pricing-endpoint-01",
  "resource": "pricing",
  "cacheable": {
    "read_from_cache": true,
    "cache_key": "pricing_$PAYLOAD.page_number",
    "duration": 600
  },
  "actionables": [
    {
      "id": 1,
      "mode": "HTTPREQUEST",
      "http": {
        "url": "https://api.example.com/pricing",
        "method": "GET"
      }
    }
  ]
}
```

### When to invalidate

Use `invalidate_cache_keys` on write-style endpoints that change the underlying data.

Typical cases:

* `INSERT`
* `UPDATE`
* `DELETE`

### What to cache

Good candidates:

* query results
* HTTP responses
* expensive aggregations

### Why it matters

Caching gives you a faster API without changing the client contract.

It is one of the quickest ways to get an obvious production win.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.lingoql.com/sub0/apis-abi/caching.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
