> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stigg.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Persistent cache, fallback, and offline mode

The Sidecar keeps serving entitlements when the Stigg API is unreachable. When it encounters startup errors (such as an invalid API key) or network errors, it continues to run and serves entitlements from:

1. The [persistent cache](#persistent-cache), if configured
2. The [global fallback strategy](#global-fallback-strategy)

In the examples below, replace `<tag>` with the latest version in the [ECR Public Gallery](https://gallery.ecr.aws/stigg/sidecar).

## Persistent cache

For cached data to survive service restarts, or to be shared across multiple instances of the Sidecar service, use Redis as the cache layer by providing the `REDIS_*` [environment variables](/documentation/high-availability-and-scale/sidecar/running-sidecar#available-options):

```shell theme={null}
docker run -it -p 80:80 \
    -e SERVER_API_KEY="<SERVER_API_KEY>" \
    -e REDIS_ENVIRONMENT_PREFIX="production" \
    -e REDIS_HOST="localhost" \
    public.ecr.aws/stigg/sidecar:<tag>
```

<Note>
  When Redis is configured, you must also run the
  [Persistent Cache Service](/documentation/high-availability-and-scale/persistent-caching)
  in a separate process to keep entitlements and usage data in Redis up to date.
  If you don’t configure Redis, you can simply run the Sidecar by itself with in-memory caching only.
</Note>

## Global fallback strategy

A [global fallback strategy](/documentation/high-availability-and-scale/local-caching-and-fallback-strategy#global-fallback-configuration) can be set by providing the Sidecar service with the `ENTITLEMENTS_FALLBACK` environment variable. It expects a JSON object in string format.

For example, the following global fallback configuration:

```json theme={null}
{
  'feature-01-templates': {
    hasAccess: true,
    usageLimit: 1000,
  },
  'feature-02-campaigns': {
    hasAccess: true,
    isUnlimited: true
  }
}
```

Can be formatted using `JSON.stringify` and then set as the value of `ENTITLEMENTS_FALLBACK` when running the container:

```shell theme={null}
docker run -it -p 80:80 \
  -e SERVER_API_KEY="<SERVER_API_KEY>" \
  -e ENTITLEMENTS_FALLBACK='{"feature-01-templates":{"hasAccess":true,"usageLimit":1000},"feature-02-campaigns":{"hasAccess":true,"isUnlimited":true}}' \
  public.ecr.aws/stigg/sidecar:<tag>
```

Entitlement check responses that were resolved from fallback values contain `isFallback: true`.

## Offline mode

During local development or testing, you might want to avoid making network requests to the Stigg API. To do this, run the Sidecar service in offline mode by setting `OFFLINE=TRUE`. When enabled, API key validation always succeeds, regardless of the key provided:

```shell theme={null}
docker run -it -p 80:80 \
    -e SERVER_API_KEY="localhost" \
    -e OFFLINE=TRUE \
    public.ecr.aws/stigg/sidecar:<tag>
```

In offline mode, the Sidecar respects the [global fallback strategy](#global-fallback-strategy), and entitlement evaluations are limited to the values defined as fallback entitlements. All other Sidecar service methods effectively become no-ops. For example:

```shell theme={null}
docker run -it -p 80:80 \
  -e SERVER_API_KEY="<SERVER_API_KEY>" \
  -e OFFLINE=TRUE \
  -e ENTITLEMENTS_FALLBACK='{"feature-01-templates":{"hasAccess":true,"usageLimit":1000},"feature-02-campaigns":{"hasAccess":true,"isUnlimited":true}}' \
  public.ecr.aws/stigg/sidecar:<tag>
```


## Related topics

- [Local caching and fallback strategy](/documentation/high-availability-and-scale/local-caching-and-fallback-strategy.md)
- [Fallback strategy](/documentation/managing-customers-and-subscriptions/entitlements/fallback-strategy.md)
- [Persistent cache](/documentation/high-availability-and-scale/persistent-caching.md)
- [JavaScript](/api-and-sdks/integration/frontend/javascript.md)
- [React](/api-and-sdks/integration/frontend/react.md)
