> For the complete documentation index, see [llms.txt](https://marrow.skeletonarmyftc.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://marrow.skeletonarmyftc.com/dev-tools/auto-bulk-caching.md).

# Auto Bulk Caching

package com.skeletonarmy.marrow

### Overview

Marrow can configure [bulk reads](https://gm0.org/en/latest/docs/software/tutorials/bulk-reads.html) for every `OpMode` automatically. You declare the mode once, and Marrow handles setup and cleanup for you.

Bulk caching is **opt-in**. By default, Marrow leaves the hubs untouched (`OFF`).

{% hint style="info" %}
**Tip:** If you're unfamiliar with bulk reads, refer to the [GM0 Bulk Reads](https://gm0.org/en/latest/docs/software/tutorials/bulk-reads.html) explanation for details.
{% endhint %}

{% hint style="danger" %}
This feature is **NOT** compatible with the [PsiKit](https://psilynx.github.io/PsiKit/#/) auto-logger, which provides its own equivalent functionality. If your OpMode uses the auto-logger, refer to [PsiKit's documentation](https://psilynx.github.io/PsiKit/#/ftc-autolog-examples) instead.
{% endhint %}

***

### Usage

#### Enable Globally

To apply a mode to every `OpMode`, set `BulkCachingSettings.defaultMode` when the event loop is created. Create a class like this anywhere:

```java
public final class AutoBulkConfig {
    @OnCreateEventLoop
    public static void configure(Context context, FtcEventLoop ftcEventLoop) {
        BulkCachingSettings.defaultMode = LynxModule.BulkCachingMode.AUTO;
    }
}
```

This enables automatic bulk reads for all OpModes that don't declare their own annotation. Because the global default is `OFF`, any `OpMode` without the annotation stays uncached until you change this value.

#### Enable for a Single OpMode

Annotate the `OpMode` class with `@BulkCaching`. With no arguments the annotation enables `AUTO` mode.

```java
@BulkCaching
@TeleOp(name = "My OpMode")
public class MyOpMode extends OpMode {
    @Override
    public void loop() {
        // Sensor values are read in bulk automatically each cycle.
    }
}
```

Explicitly choose a mode by passing it to the annotation:

```java
// Automatic bulk reads
@BulkCaching(LynxModule.BulkCachingMode.AUTO)

// Manual bulk reads
@BulkCaching(LynxModule.BulkCachingMode.MANUAL)

// Disable bulk caching for this OpMode only
@BulkCaching(LynxModule.BulkCachingMode.OFF)
```

{% hint style="info" %}
**Tip:** Setting a mode on a specific `OpMode` overrides the global config for that `OpMode` only. This is not needed if you enable bulk caching globally.
{% endhint %}

{% hint style="danger" %}
In `MANUAL` mode the cache is not refreshed on its own. Call `LynxUtil.clearBulkCache(hardwareMap)` once per loop, otherwise sensor readings will be stale.
{% endhint %}

***

### Manual Control

The annotation and global setting cover most use cases. `LynxUtil` is available when you need direct control at runtime.

#### Set Bulk Caching Mode

Set the mode for all Lynx modules in a given `HardwareMap`.

```java
LynxUtil.setBulkCachingMode(hardwareMap, LynxModule.BulkCachingMode.AUTO);
```

#### Clear Bulk Cache

Clear the bulk data cache for all Lynx modules. In `MANUAL` mode this is required each loop so subsequent sensor readings are up-to-date.

```java
LynxUtil.clearBulkCache(hardwareMap);
```

{% hint style="info" %}
**Tip:** Clearing the cache is unnecessary in `AUTO` mode, as it automatically updates data each cycle. If you're unfamiliar with bulk reads, refer to the [GM0 Bulk Reads](https://gm0.org/en/latest/docs/software/tutorials/bulk-reads.html) explanation for details.
{% endhint %}


---

# 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 following URL with the `ask` and `goal` query parameters:

```
GET https://marrow.skeletonarmyftc.com/dev-tools/auto-bulk-caching.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 `build a script that syncs our docs to a CMS` 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.
