Query caching

    Query caching works for all backend data sources, and queries sent through the data source proxy. You can enable the cache globally and configure the cache duration (also called Time to Live, or TTL).

    The following cache backends are available: in-memory, Redis, and Memcached.

    When a panel queries a cached data source, the time until this query fetches fresh data is determined by the panel’s interval. This means that wider panels and dashboards with shorter time ranges fetch new data more frequently than narrower panels and dashboards with longer time ranges.

    Interval is visible in a panel’s query options. It is calculated like this: . Max data points are calculated based on the width of the panel. For example, a full-width panel on a dashboard with a time range of last 7 days will retrieve fresh data every 10 minutes. In this example, cached data for this panel will be served for up to 10 minutes before Grafana queries the data source again and returns new data.

    • Faster dashboard load times, especially for popular dashboards.
    • Reduced API costs.

    Query caching works for all , and it works for the following built-in data sources:

    • CloudWatch
    • Google Cloud Monitoring
    • InfluxDB
    • Microsoft SQL Server
    • MySQL
    • Postgres
    • Tempo

    Some data sources, such as Elasticsearch, Prometheus, and Loki, cache queries themselves, so Grafana query caching does not improve performance.

    Query caching also works for all data sources that include a backend. More specifically, caching works with data sources that extend the class in the plugins SDK.

    To tell if a data source works with query caching, follow the instructions below to Enable and Configure query caching. If caching is enabled in Grafana but the Caching tab is not visible for the given data source, then query caching is not available for that data source.

    You must be an Org admin or Grafana admin to enable query caching for a data source. For more information on Grafana roles and permissions, visit the Permissions page.

    1. In the data source list, click the data source that you want to turn on caching for.
    2. In the Cache tab, click Enable.
    3. Open the Cache tab.
    4. Press the Enable button.
    5. (Optional) Choose a custom TTL for that data source. If you skip this step, then Grafana uses the default TTL.

    Note: If query caching is enabled and the Cache tab is not visible in a data source’s settings, then query caching is not available for that data source.

    To configure global settings for query caching, refer the the .

    To disable query caching for a single data source:

    1. On the side menu, click Configuration > Data Sources.
    2. In the data source list, click the data source that you want to turn off caching for.

    To disable query caching for an entire Grafana instance, set the enabled flag to in the . You will no longer see the Cache tab on any data sources, and no data source queries will be cached.

    If a data source query request contains an X-Cache-Skip header, then Grafana skips the caching middleware, and does not search the cache for a response. This can be particularly useful when debugging data source queries using cURL.