| --- | |
| title: Caching | |
| hide_title: true | |
| sidebar_position: 3 | |
| version: 1 | |
| --- | |
| # Caching | |
| ## Semantic containment cache | |
| `SEMANTIC_LAYER_CONTAINMENT_CACHE` is experimental and default-off. Enabling | |
| the flag alone is insufficient: enable `SEMANTIC_LAYERS`, use a provider that | |
| explicitly delegates containment caching, and configure persistent shared | |
| `DATA_CACHE_CONFIG` plus Redis-backed `DISTRIBUTED_COORDINATION_CONFIG` on every | |
| web and worker process. The default `NullCache` data backend disables containment. | |
| See the [semantic containment setup and validation guide](/developer-docs/extensions/extension-points/semantic-layers#semantic-result-containment-caching) | |
| for the two-backend example, supported backends, timeout semantics, emitted | |
| metrics and concurrency limitations. Restart every web/worker process after | |
| configuration changes and verify the effective-state metric before a canary. | |
| The reader fence uses identity format `v4` and matches a per-write nonce in each | |
| descriptor/result pair. Existing `v3` entries become cold misses; they need no | |
| manual deletion. During a mixed-version rollout, old workers still use the old | |
| unfenced path, so finish the web/worker rollout before validating the fence. | |
| Monitor `semantic_cache.containment.fence_reject` alongside misses and coordination | |
| failures during forced-refresh testing: rejected pairs must fall back to another | |
| valid candidate or the provider, never serve the stale writer's mismatched value. | |
| Pruning removes invalid descriptors after rechecking the current pair and leaves | |
| payloads to their configured TTL. Preserve the validation hold until the | |
| split-store process-pause scenario and provider-result comparisons pass. | |
| Filtering and rollup preserve nullable integer, decimal and timestamp values; | |
| unsupported conversions or overflowing aggregates fall back to the provider. | |
| The ORM view's nonempty host-supplied `metadata_cache_token` participates in | |
| containment identity. Missing, empty, or invalid host tokens bypass containment | |
| and execute the provider, even if older entries exist. A provider's optional token | |
| cannot substitute for the host generation. Containment requires the host metadata | |
| cache-generation binding; no metadata-refresh adapter is required. | |
| To roll back, disable `SEMANTIC_LAYER_CONTAINMENT_CACHE`, restart every process, | |
| and confirm `semantic_cache.containment.enabled` is zero and provider queries | |
| continue. This best-effort cache's fallback behavior does not change the other | |
| cache backends' availability requirements below. | |
| :::note | |
| When a cache backend is configured, Superset expects it to remain available. Operations will | |
| fail if the configured backend becomes unavailable rather than silently degrading. This | |
| fail-fast behavior ensures operators are immediately aware of infrastructure issues. | |
| ::: | |
| Superset uses [Flask-Caching](https://flask-caching.readthedocs.io/) for caching purposes. | |
| Flask-Caching supports various caching backends, including Redis (recommended), Memcached, | |
| SimpleCache (in-memory), MinIO/S3, or the local filesystem. | |
| [Custom cache backends](https://flask-caching.readthedocs.io/en/latest/#custom-cache-backends) are also supported. | |
| Caching can be configured by providing dictionaries in | |
| `superset_config.py` that comply with [the Flask-Caching config specifications](https://flask-caching.readthedocs.io/en/latest/#configuring-flask-caching). | |
| The following cache configurations can be customized in this way: | |
| - Dashboard filter state (required): `FILTER_STATE_CACHE_CONFIG`. | |
| - Explore chart form data (required): `EXPLORE_FORM_DATA_CACHE_CONFIG` | |
| - Metadata cache (optional): `CACHE_CONFIG` | |
| - Charting data queried from datasets (optional): `DATA_CACHE_CONFIG` | |
| For example, to configure the filter state cache using Redis: | |
| ```python | |
| FILTER_STATE_CACHE_CONFIG = { | |
| 'CACHE_TYPE': 'RedisCache', | |
| 'CACHE_DEFAULT_TIMEOUT': 86400, | |
| 'CACHE_KEY_PREFIX': 'superset_filter_cache', | |
| 'CACHE_REDIS_URL': 'redis://localhost:6379/0' | |
| } | |
| ``` | |
| ## Dependencies | |
| In order to use dedicated cache stores, additional python libraries must be installed | |
| - For Redis: we recommend the [redis](https://pypi.python.org/pypi/redis) Python package | |
| - Memcached: we recommend using [pylibmc](https://pypi.org/project/pylibmc/) client library as | |
| `python-memcached` does not handle storing binary data correctly. | |
| - MinIO (S3): we recommend using the [minio-flask-cache](https://github.com/greggailly/minio-flask-cache) package | |
| These libraries can be installed using pip. | |
| ## Fallback Metastore Cache | |
| Note, that some form of Filter State and Explore caching are required. If either of these caches | |
| are undefined, Superset falls back to using a built-in cache that stores data in the metadata | |
| database. While it is recommended to use a dedicated cache, the built-in cache can also be used | |
| to cache other data. | |
| For example, to use the built-in cache to store chart data, use the following config: | |
| ```python | |
| DATA_CACHE_CONFIG = { | |
| "CACHE_TYPE": "SupersetMetastoreCache", | |
| "CACHE_KEY_PREFIX": "superset_results", # make sure this string is unique to avoid collisions | |
| "CACHE_DEFAULT_TIMEOUT": 86400, # 60 seconds * 60 minutes * 24 hours | |
| } | |
| ``` | |
| ## Chart Cache Timeout | |
| The cache timeout for charts may be overridden by the settings for an individual chart, dataset, or | |
| database. Each of these configurations will be checked in order before falling back to the default | |
| value defined in `DATA_CACHE_CONFIG`. | |
| Note, that by setting the cache timeout to `-1`, caching for charting data can be disabled, either | |
| per chart, dataset or database, or by default if set in `DATA_CACHE_CONFIG`. | |
| The datasource column-values and compatibility endpoints skip cache reads and writes when | |
| their effective timeout is `-1`. They use the datasource timeout (for SQL datasets, falling | |
| back to the database timeout), then the **top-level** `CACHE_DEFAULT_TIMEOUT` when that value | |
| is unset or zero. They do not use `DATA_CACHE_CONFIG["CACHE_DEFAULT_TIMEOUT"]` for this | |
| fallback, so setting only that nested default to `-1` does not disable these endpoints. | |
| With caching disabled, each request fetches fresh values or compatibility results from the source. | |
| This bypass does not delete existing entries. Earlier versions could write entries without | |
| expiry on Redis while the timeout was `-1`; column-value entries can become readable again | |
| when caching is re-enabled unless the datasource has been edited. Compatibility keys include | |
| the datasource modification time, matching column-value keys. Adding this key component makes | |
| older compatibility entries unreachable and causes a one-time cache miss for compatibility lists. | |
| Before re-enabling, invalidate affected `col_values:` entries through your deployment's | |
| cache-management tooling. Obsolete `compatible:` entries can also be removed to reclaim space. | |
| Account for your configured cache-key prefix when managing either kind of entry. | |
| Native filter option queries (the dropdown values for native filters) go through this same | |
| chart-data cache, but their freshness needs often differ from regular chart queries, especially for | |
| datasets whose visible values change frequently, including RLS-constrained datasets. Set | |
| `NATIVE_FILTER_OPTIONS_CACHE_TIMEOUT` in `superset_config.py` to give these queries a dedicated | |
| timeout, checked before the chart/dataset/database chain and the `DATA_CACHE_CONFIG` default above: | |
| ```python | |
| NATIVE_FILTER_OPTIONS_CACHE_TIMEOUT = 60 # seconds | |
| ``` | |
| - `None` (default): native filter option queries fall through to the normal | |
| chart/dataset/database/`DATA_CACHE_CONFIG` resolution chain. | |
| - `-1`: disables caching for native filter option queries entirely. | |
| - `0`: passed directly to the cache backend; behavior is backend-specific, so use `-1` if the intent | |
| is to disable caching. | |
| - A positive integer: cache native filter option queries for that many seconds. | |
| This setting only applies to requests detected as native filter option queries. It takes precedence | |
| over the per-chart/dataset/database timeouts, but not over an explicit per-request | |
| `custom_cache_timeout` override (e.g. "Force refresh"). | |
| ## Async Query Result Cache TTL | |
| When [Global Async Queries](/admin-docs/configuration/configuring-superset#feature-flags) is | |
| enabled, a chart-data request that runs asynchronously does not return the result inline. Instead the | |
| query executes on a background task that **writes the result to the data cache**, and the browser | |
| then re-issues the same request to read that result back out of the cache once the task succeeds. | |
| This read-back is what makes the result-cache TTL matter for correctness, not just performance: if | |
| the effective TTL is shorter than the full async round trip (task execution + the client's poll | |
| interval + the re-fetch), the entry can be **evicted before the client reads it**, leaving the chart | |
| stuck re-running instead of loading. To prevent this, async requests floor their result-cache TTL to | |
| `GLOBAL_ASYNC_QUERIES_MIN_CACHE_TTL` (seconds, default `300` — five minutes): | |
| ```python | |
| GLOBAL_ASYNC_QUERIES_MIN_CACHE_TTL = 300 # seconds | |
| ``` | |
| How the floor interacts with the timeouts above: | |
| - It applies **only to async execution**. Synchronous `/chart/data` requests keep their normal | |
| chart/dataset/database/`DATA_CACHE_CONFIG` timeout even when Global Async Queries is enabled. | |
| - A **longer** effective TTL from that chain is kept as-is — the floor only raises TTLs that are | |
| shorter than it. | |
| - A TTL of `0` ("cache forever") is left untouched. | |
| Tuning guidance: raise this value if your workload's async round trip can exceed five minutes (very | |
| long-running queries or slow warehouses), otherwise those charts may intermittently fail to load. Be | |
| aware of the trade-off — because the floor can raise an async result's TTL above a shorter cache | |
| retention policy, it keeps async results in the cache longer and modestly increases cache | |
| (Redis/Valkey) usage. Do not lower it below your worst-case async round trip. | |
| ## Limiting Cached Result Size | |
| Very large chart or SQL query results can flood the cache backend (Redis/Memcached), evicting many | |
| smaller useful entries or exhausting memory. To cap the size of any single value written to the data | |
| cache, set `DATA_CACHE_MAX_VALUE_SIZE` (in bytes) in `superset_config.py`: | |
| ```python | |
| DATA_CACHE_MAX_VALUE_SIZE = 10 * 1024 * 1024 # 10 MB | |
| ``` | |
| When a result's serialized size exceeds this threshold it is not written to the data cache — the | |
| chart still renders, but the next load re-queries the datasource instead of getting a cache hit. The | |
| `skip_cache_value_too_large` statsd metric is incremented each time this happens. Set to `None` (the | |
| default) to disable the check. | |
| ## Warming the Data Cache | |
| Dataset cache-warming requests identify a dataset using both `db_name` and `table_name`. | |
| For the legacy `GET /warm_up_cache/` endpoint, pass these names as query parameters. | |
| The table must belong to the named database; if either name does not match, the endpoint | |
| returns HTTP 404. New integrations can use `PUT /api/v1/dataset/warm_up_cache`. | |
| ## SQL Lab Query Results | |
| Caching for SQL Lab query results is used when async queries are enabled and is configured using | |
| `RESULTS_BACKEND`. | |
| Note that this configuration does not use a flask-caching dictionary for its configuration, but | |
| instead requires a cachelib object. | |
| See [Async Queries via Celery](/admin-docs/configuration/async-queries-celery) for details. | |
| ## Celery beat | |
| Superset has a Celery task that will periodically warm up the cache based on different strategies. | |
| To use it, add the following to your `superset_config.py`: | |
| ```python | |
| from celery.schedules import crontab | |
| from superset.config import CeleryConfig | |
| # User that will be used to authenticate and render dashboards for cache warmup | |
| SUPERSET_CACHE_WARMUP_USER = "user_with_permission_to_dashboards" | |
| # Extend the default CeleryConfig to add cache warmup schedule | |
| class CustomCeleryConfig(CeleryConfig): | |
| beat_schedule = { | |
| **CeleryConfig.beat_schedule, | |
| 'cache-warmup-hourly': { | |
| 'task': 'cache-warmup', | |
| 'schedule': crontab(minute=0, hour='*'), # hourly | |
| 'kwargs': { | |
| 'strategy_name': 'top_n_dashboards', | |
| 'top_n': 5, | |
| 'since': '7 days ago', | |
| }, | |
| }, | |
| } | |
| CELERY_CONFIG = CustomCeleryConfig | |
| ``` | |
| This will cache the top 5 most popular dashboards every hour. For other | |
| strategies, check the `superset/tasks/cache.py` file. | |
| ### Warming Up Native Filter Options | |
| Native filter Value-type dropdown option queries (e.g. `SELECT DISTINCT column FROM table`) are | |
| cached the same way as chart data, via `DATA_CACHE_CONFIG`. However, the strategies above only warm | |
| up chart render queries, so the first user to open a dashboard's filter dropdown after a cache entry | |
| expires still triggers a fresh database query. | |
| The `native_filter_options` strategy pre-populates the cache for these dropdown queries. It reads | |
| each dashboard's `native_filter_configuration`, builds the same `filter_select` chart-data query the | |
| frontend would send, and executes it as the configured `SUPERSET_CACHE_WARMUP_USER`: | |
| ```python | |
| class CustomCeleryConfig(CeleryConfig): | |
| beat_schedule = { | |
| **CeleryConfig.beat_schedule, | |
| 'cache-warmup-native-filters': { | |
| 'task': 'cache-warmup', | |
| 'schedule': crontab(minute=0, hour=3), # daily at 03:00 | |
| 'kwargs': { | |
| 'strategy_name': 'native_filter_options', | |
| 'dashboard_ids': [1, 2, 3], | |
| }, | |
| }, | |
| } | |
| ``` | |
| Requirements and limitations: | |
| - `SUPERSET_CACHE_WARMUP_USER` must be set to a user with access to the dashboards and datasets | |
| referenced by the native filters. | |
| - `DATA_CACHE_CONFIG` must use a backend that actually persists entries (Redis recommended); the | |
| default `NullCache` discards writes, so warming has nothing to warm. The effective timeout also | |
| needs to be positive — `NATIVE_FILTER_OPTIONS_CACHE_TIMEOUT = -1` disables cache writes for these | |
| queries entirely, even with a working backend. | |
| - Schedule the warm-up at least as often as the effective native filter cache timeout (whichever of | |
| `NATIVE_FILTER_OPTIONS_CACHE_TIMEOUT`, the chart/dataset/database timeout, or `DATA_CACHE_CONFIG`'s | |
| default applies). A looser schedule still leaves a window of cold, unwarmed queries between expiry | |
| and the next run — the daily example above assumes a TTL of a day or more. | |
| - Cache entries are warmed under the warm-up user's own cache partition, the same entry that user | |
| would create by opening the filter dropdown manually. Users with a different role set or row-level | |
| security context may still see a cache miss on first load. | |
| - Cascading/dependent native filters and search-term variants of filter option queries are not | |
| warmed by this strategy. | |
| ## Caching Thumbnails | |
| This is an optional feature that can be turned on by activating its [feature flag](/admin-docs/configuration/configuring-superset#feature-flags) on config: | |
| ``` | |
| FEATURE_FLAGS = { | |
| "THUMBNAILS": True, | |
| "THUMBNAILS_SQLA_LISTENERS": True, | |
| } | |
| ``` | |
| By default thumbnails are rendered as the user who requests them. Anonymous requests have no user | |
| to render as, so they get no thumbnail unless you add a fallback executor, for example | |
| `THUMBNAIL_EXECUTORS = [ExecutorType.CURRENT_USER, FixedExecutor("admin")]`. | |
| To always render thumbnails as a fixed user (`admin` in this example), use the following configuration: | |
| ```python | |
| from superset.tasks.types import FixedExecutor | |
| THUMBNAIL_EXECUTORS = [FixedExecutor("admin")] | |
| ``` | |
| When using `ExecutorType.EDITOR`, thumbnails are rendered as a physical user represented by | |
| the dashboard or chart editors. Superset prioritizes the last modifier, then the creator, | |
| then the first direct user editor, then a deterministic user from editor roles or groups. | |
| For this feature you will need a cache system and celery workers. All thumbnails are stored on cache | |
| and are processed asynchronously by the workers. | |
| An example config where images are stored on S3 could be: | |
| ```python | |
| from flask import Flask | |
| from s3cache.s3cache import S3Cache | |
| ... | |
| class CeleryConfig(object): | |
| broker_url = "redis://localhost:6379/0" | |
| imports = ( | |
| "superset.sql_lab", | |
| "superset.tasks.thumbnails", | |
| ) | |
| result_backend = "redis://localhost:6379/0" | |
| worker_prefetch_multiplier = 10 | |
| task_acks_late = True | |
| CELERY_CONFIG = CeleryConfig | |
| def init_thumbnail_cache(app: Flask) -> S3Cache: | |
| return S3Cache("bucket_name", 'thumbs_cache/') | |
| THUMBNAIL_CACHE_CONFIG = init_thumbnail_cache | |
| ``` | |
| Using the above example cache keys for dashboards will be `superset_thumb__dashboard__{ID}`. You can | |
| override the base URL that the headless browser uses to reach Superset using: | |
| ``` | |
| WEBDRIVER_BASEURL = "https://superset.company.com" | |
| ``` | |
| To control which user account is used for rendering thumbnails and warming up caches, configure | |
| `THUMBNAIL_EXECUTORS` and `CACHE_WARMUP_EXECUTORS`. Each accepts a list of executor types (which | |
| resolve to an editor, creator, modifier, or the currently-logged-in user) and/or a | |
| `FixedExecutor` pinned to a specific username. By default, thumbnails render as the current user | |
| (`ExecutorType.CURRENT_USER`) and cache warmup uses editor-based execution | |
| (`ExecutorType.EDITOR`) where executor-based cache warmup is used. | |
| To force both to run as a dedicated service account (`admin` in this example): | |
| ```python | |
| from superset.tasks.types import ExecutorType, FixedExecutor | |
| THUMBNAIL_EXECUTORS = [FixedExecutor("admin")] | |
| CACHE_WARMUP_EXECUTORS = [FixedExecutor("admin")] | |
| ``` | |
| Use a dedicated read-only service account here rather than a personal admin account, so that | |
| thumbnail rendering and cache warmup tasks don't fail if a specific user's credentials change. | |
| Thumbnails are rendered with Playwright and a headless Chromium browser. Extra Chromium launch | |
| arguments can be set using `WEBDRIVER_OPTION_ARGS`. You can implement a custom function to | |
| authenticate the Playwright browser context. The default function uses the `flask-login` session | |
| cookie. A custom function replaces that default, so it must authenticate as `user` itself. | |
| Here's an example of a custom function: | |
| ```python | |
| from typing import TYPE_CHECKING | |
| if TYPE_CHECKING: | |
| from flask_appbuilder.security.sqla.models import User | |
| from playwright.sync_api import BrowserContext | |
| def auth_browser_context( | |
| browser_context: "BrowserContext", user: "User" | |
| ) -> "BrowserContext": | |
| # This replaces Superset's default session-cookie login, so it must | |
| # authenticate as `user` itself. For example, send a bearer token: | |
| # `get_token_for_user` is a placeholder for your own token lookup. | |
| token = get_token_for_user(user) | |
| browser_context.set_extra_http_headers({"Authorization": f"Bearer {token}"}) | |
| return browser_context | |
| ``` | |
| Then on configuration: | |
| ``` | |
| WEBDRIVER_AUTH_FUNC = auth_browser_context | |
| ``` | |
| To replace the authentication logic entirely, subclass `superset.utils.machine_auth.MachineAuthProvider`, | |
| override `authenticate_browser_context()`, and set `MACHINE_AUTH_PROVIDER_CLASS` to the fully-qualified dotted path of your class (for example, `"myapp.auth.MyMachineAuthProvider"`). | |
| ### Refreshing successfully-rendered thumbnails | |
| Successfully-rendered thumbnails remain cached until the cache backend expires or evicts them. | |
| On backends without TTL eviction (for example S3), a stale — or valid-but-blank — capture can | |
| therefore be served indefinitely to callers that do not pass `force=true`. | |
| `THUMBNAIL_UPDATED_CACHE_TTL` triggers a refresh when an eligible request finds a | |
| successfully-rendered thumbnail older than this limit: | |
| ```python | |
| from datetime import timedelta | |
| # Recompute a successfully-rendered thumbnail once it is older than 7 days (the default, | |
| # matching THUMBNAIL_CACHE_CONFIG's CACHE_DEFAULT_TIMEOUT). | |
| THUMBNAIL_UPDATED_CACHE_TTL = int(timedelta(days=7).total_seconds()) | |
| ``` | |
| - **Opt out:** set `THUMBNAIL_UPDATED_CACHE_TTL = 0` (or `None`) to disable this freshness check | |
| (the previous behavior). Retention then falls back to the cache backend's own expiry — e.g. | |
| `THUMBNAIL_CACHE_CONFIG`'s `CACHE_DEFAULT_TIMEOUT` (7 days by default) — so a rendered thumbnail | |
| is only served *indefinitely* on a no-eviction backend such as S3. | |
| - **Affected paths:** the freshness check applies to the on-demand dashboard screenshot endpoint | |
| (`POST /api/v1/dashboard/<pk>/cache_dashboard_screenshot/`) and to dashboard thumbnails | |
| recomputed by `superset compute-thumbnails` without `--force`. The high-traffic card-list | |
| thumbnail endpoints and the chart on-demand screenshot endpoint are intentionally excluded and | |
| continue using the cache backend's retention policy. A dashboard refresh without `force=true` | |
| retains the last valid image while rendering and during error backoff. Concurrent forced | |
| requests can share an imageless refresh already in progress or its completed replacement. | |
| A refresh still carrying older bytes is replaced with an imageless generation, so the | |
| forced request's image URL waits for the new capture. | |
| - **Retained image:** a refresh can only keep serving a capture that the cache backend still | |
| holds when it turns stale. This holds on backends without TTL eviction (for example S3), when | |
| `THUMBNAIL_CACHE_CONFIG`'s `CACHE_DEFAULT_TIMEOUT` is `0`, or when that timeout exceeds this TTL. | |
| With the defaults (both 7 days), an evicting backend such as Redis expires a capture as it | |
| turns stale, so the refresh renders without an image, as a first render does. On a backend that | |
| keeps the capture, the on-demand endpoint can still find it for about `CACHE_DEFAULT_TIMEOUT` | |
| after it turns stale (indefinitely when that timeout is `0`); a later request renders without it. | |
| - **Clock skew:** cache timestamps are naive local times written by the host that rendered the | |
| image, so run web servers and thumbnail workers with the same `TZ` and keep this TTL above any | |
| clock offset between them. A worker clock running ahead of the web servers only postpones the | |
| refresh by that offset; one running behind by more than the TTL makes every fresh capture look | |
| expired, so each request triggers another render. | |
| - **Rollout:** roll thumbnail workers before web servers when enabling this. During a mixed deploy | |
| a new web server can enqueue a refresh that an older worker skips, leaving the thumbnail stale | |
| until the worker pool finishes rolling (it self-heals afterward). | |
| ## ETag Support for Thumbnails | |
| Thumbnail and screenshot endpoints return `ETag` response headers based on the cached content digest. Clients can use conditional requests to avoid downloading unchanged images: | |
| ``` | |
| GET /api/v1/chart/42/thumbnail/ | |
| If-None-Match: "abc123..." | |
| → 304 Not Modified (if unchanged) | |
| → 200 OK (with new image if changed) | |
| ``` | |
| This is particularly useful for embedded dashboards and external integrations that periodically poll for updated screenshots — unchanged thumbnails return immediately with no payload. | |
| ## Distributed Coordination Backend | |
| Superset supports an optional distributed coordination (`DISTRIBUTED_COORDINATION_CONFIG`) for | |
| high-performance distributed operations. This configuration enables: | |
| - **Distributed locking**: Moves lock operations from the metadata database to Redis, improving | |
| performance and reducing metastore load | |
| - **Event-driven notifications**: Task completion and abort signals are delivered over Redis | |
| **Streams**, so waiters (sync join-and-wait, task-dependency DAGs, abort listeners) wake when a | |
| signal lands instead of polling the metadata database. Because stream entries are persisted, a | |
| waiter that reads slightly late, reconnects, or fails over still receives the signal. Without this | |
| backend, these operations poll the metadata database instead. | |
| :::note | |
| This requires Redis or Valkey specifically—it uses Redis-specific features (Streams, pub/sub, | |
| `SET NX EX`) that are not available in general Flask-Caching backends. | |
| ::: | |
| Each signal stream keeps only its latest entry and is given a TTL, so signal streams for tasks that | |
| are never awaited do not accumulate in Redis/Valkey. Set the retention window with | |
| `DISTRIBUTED_COORDINATION_SIGNAL_TTL` (seconds, default 24 hours): | |
| ```python | |
| DISTRIBUTED_COORDINATION_SIGNAL_TTL = 24 * 60 * 60 | |
| ``` | |
| ### Configuration | |
| The distributed coordination uses Flask-Caching style configuration for consistency with other cache | |
| backends. Configure `DISTRIBUTED_COORDINATION_CONFIG` in `superset_config.py`: | |
| ```python | |
| DISTRIBUTED_COORDINATION_CONFIG = { | |
| "CACHE_TYPE": "RedisCache", | |
| "CACHE_REDIS_HOST": "localhost", | |
| "CACHE_REDIS_PORT": 6379, | |
| "CACHE_REDIS_DB": 0, | |
| "CACHE_REDIS_PASSWORD": "", # Optional | |
| } | |
| ``` | |
| For Redis Sentinel deployments: | |
| ```python | |
| DISTRIBUTED_COORDINATION_CONFIG = { | |
| "CACHE_TYPE": "RedisSentinelCache", | |
| "CACHE_REDIS_SENTINELS": [("sentinel1", 26379), ("sentinel2", 26379)], | |
| "CACHE_REDIS_SENTINEL_MASTER": "mymaster", | |
| "CACHE_REDIS_SENTINEL_PASSWORD": None, # Sentinel password (if different) | |
| "CACHE_REDIS_PASSWORD": "", # Redis password | |
| "CACHE_REDIS_DB": 0, | |
| } | |
| ``` | |
| For SSL/TLS connections: | |
| ```python | |
| DISTRIBUTED_COORDINATION_CONFIG = { | |
| "CACHE_TYPE": "RedisCache", | |
| "CACHE_REDIS_HOST": "redis.example.com", | |
| "CACHE_REDIS_PORT": 6380, | |
| "CACHE_REDIS_SSL": True, | |
| "CACHE_REDIS_SSL_CERTFILE": "/path/to/client.crt", | |
| "CACHE_REDIS_SSL_KEYFILE": "/path/to/client.key", | |
| "CACHE_REDIS_SSL_CA_CERTS": "/path/to/ca.crt", | |
| } | |
| ``` | |
| By default, connections opened for `DISTRIBUTED_COORDINATION_CONFIG` have no socket | |
| timeout. This can be overridden with `CACHE_REDIS_SOCKET_TIMEOUT` and | |
| `CACHE_REDIS_SOCKET_CONNECT_TIMEOUT`, both in seconds: | |
| ```python | |
| DISTRIBUTED_COORDINATION_CONFIG = { | |
| "CACHE_TYPE": "RedisCache", | |
| "CACHE_REDIS_HOST": "localhost", | |
| "CACHE_REDIS_PORT": 6379, | |
| "CACHE_REDIS_SOCKET_TIMEOUT": 5, # seconds | |
| "CACHE_REDIS_SOCKET_CONNECT_TIMEOUT": 5, # seconds | |
| } | |
| ``` | |
| These apply to `RedisSentinelCache` connections as well, covering both the sentinel-node | |
| connections and the resolved master connection. | |
| ### Distributed Lock TTL | |
| You can configure the default lock TTL (time-to-live) in seconds. Locks automatically expire after | |
| this duration to prevent deadlocks from crashed processes: | |
| ```python | |
| DISTRIBUTED_LOCK_DEFAULT_TTL = 30 # Default: 30 seconds | |
| ``` | |
| Individual lock acquisitions can override this value when needed. | |
| ### Database-Only Mode | |
| When `DISTRIBUTED_COORDINATION_CONFIG` is not configured, Superset uses database-backed operations: | |
| - **Locking**: Uses the KeyValue table with periodic cleanup of expired entries | |
| - **Event notifications**: Uses database polling instead of pub/sub | |
| While database-backed operations work reliably, the Redis backend is recommended for production | |
| deployments where low latency and reduced database load are important. | |
| :::resources | |
| - [Blog: The Data Engineer's Guide to Lightning-Fast Superset Dashboards](https://preset.io/blog/the-data-engineers-guide-to-lightning-fast-apache-superset-dashboards/) | |
| - [Blog: Accelerating Dashboards with Materialized Views](https://preset.io/blog/accelerating-apache-superset-dashboards-with-materialized-views/) | |
| ::: |