> For the complete documentation index, see [llms.txt](https://docs.heisenware.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.heisenware.com/reference/functions/storage/buffer.md).

# Buffer

The buffer class holds a fixed number of values in order, from front to back. Once it is full, every push drops a value at the opposite end, so the buffer always holds the most recent `capacity` values: a sliding window, for example the last 100 data points of a live chart. React to a full buffer with `onFull` and clear it in reaction to get a tumbling window (one batch per `capacity` values), or push at the back and pop at the front to use it as a queue.

The values live in memory only: after a restart of the platform the instance is there again, empty. This class requires an instance. The code class name is `Buffer`.

### `create`

Creates a new buffer instance with a fixed capacity.

#### Parameters

<table><thead><tr><th width="150">Input</th><th>Description</th><th width="100">Type</th></tr></thead><tbody><tr><td><code>capacity</code></td><td>The maximum number of values the buffer holds, at least 1. Default 100.</td><td>integer</td></tr></tbody></table>

#### Output

Returns the name of the created instance. Creating a name that already exists returns it unchanged, with its original capacity.

#### Example

```yaml
# capacity
10
```

### `delete`

Removes the buffer instance, for every App that uses it.

#### Parameters

None.

#### Output

Returns `true` when the instance is deleted.

{% hint style="danger" %}

#### Permanent data loss

Deleting removes the instance configuration. All buffered data is permanently lost.
{% endhint %}

### `pushBack`

Adds a value at the back of the buffer. If the buffer is full, the value at the front (the oldest one pushed at the back) is dropped first.

#### Parameters

<table><thead><tr><th width="150">Input</th><th>Description</th><th width="100">Type</th></tr></thead><tbody><tr><td><code>value</code></td><td>The value or object to add. A missing value is refused.</td><td>any</td></tr></tbody></table>

#### Output

Returns the number of values held after the push as an integer.

#### Example

```yaml
# value
Another new item
```

### `pushFront`

Adds a value at the front of the buffer. If the buffer is full, the value at the back is dropped first.

#### Parameters

<table><thead><tr><th width="150">Input</th><th>Description</th><th width="100">Type</th></tr></thead><tbody><tr><td><code>value</code></td><td>The value or object to add. A missing value is refused.</td><td>any</td></tr></tbody></table>

#### Output

Returns the number of values held after the push as an integer.

### `popFront`

Removes and returns the value at the front of the buffer.

#### Parameters

None.

#### Output

Returns the removed value or object. Fails with `Buffer is empty` when there is none.

### `popBack`

Removes and returns the value at the back of the buffer.

#### Parameters

None.

#### Output

Returns the removed value or object. Fails with `Buffer is empty` when there is none.

### `peekFront`

Returns the value at the front without removing it.

#### Parameters

None.

#### Output

Returns the front value or object. Fails with `Buffer is empty` when there is none.

### `peekBack`

Returns the value at the back without removing it.

#### Parameters

None.

#### Output

Returns the back value or object. Fails with `Buffer is empty` when there is none.

### `getBuffer`

Returns all values currently inside the buffer as a standard array, ordered from front to back.

#### Parameters

None.

#### Output

Returns a copy of the stored values as an array.

### `getSize`

Returns the current number of values stored in the buffer.

#### Parameters

None.

#### Output

Returns the current value count as an integer, from 0 to the capacity.

### `getCapacity`

Returns the maximum number of values the buffer can hold.

#### Parameters

None.

#### Output

Returns the capacity set at creation as an integer.

### `isFull`

Checks whether the buffer holds as many values as its capacity.

#### Parameters

None.

#### Output

Returns `true` when the buffer is full, otherwise `false`.

### `isEmpty`

Checks whether the buffer holds no value.

#### Parameters

None.

#### Output

Returns `true` when the buffer is empty, otherwise `false`.

### `clear`

Removes all contents and empties the buffer. The capacity stays.

#### Parameters

None.

#### Output

Returns `true`.

## Events

Triggering an event executor subscribes it; triggering it again with the same inputs changes nothing. The payload arrives on the executor's event outputs, not on its return. The subscription pauses while the App is stopped and ends with its scope: a user's with the user's last connection, a shared one never by itself. To end it by hand, choose **Stop listening** on the executor's event input; the next trigger subscribes again. See [Backend events](https://docs.heisenware.com/concepts/backend-events.md).

### `onFull`

Subscribes to the `full` event. The listener is called after every push that leaves the buffer full, which means on every push once the capacity is reached (a sliding window). Clear the buffer in reaction to get one call per `capacity` pushes (a tumbling window).

#### Parameters

<table><thead><tr><th width="150">Input</th><th>Description</th><th width="100">Type</th></tr></thead><tbody><tr><td><code>listener</code></td><td>The listener.<br>Payload: <code>values</code>, all values held, from front to back.</td><td>callback</td></tr></tbody></table>

#### Output

Returns `true` once the executor is listening. The values arrive on the event outputs.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.heisenware.com/reference/functions/storage/buffer.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
