Can I cache with the API query endpoints?

Knowledge Drop

Last tested: May 12, 2020
 

The `run_query` and `run_inline_query` API endpoints can pull from cache in the following ways:

cache=true : use cache if it is available
cache=false : don't use cache even if it is available
cache_only=true : retrieve any results from cache even if the results have expired

However, these endpoints do not set cache.

If you run the `run_inline_query` endpoint on the same query twice in a row, the first call will not cache the query for the second call. This is because the `run_inline_query` endpoint is analogous to downloading All Results in the UI (although you have to set a row limit for the call, that row limit can be arbitrarily large), and Looker does not cache unlimited results.

If you want to set cache via the API, you'll want to use the async query endpoints: `create_query_task` and `query_task_results`. The Looker UI always uses async queries for explores and visualizations, so these endpoints are more similar to UI query behavior. it's important to make sure that the results_format parameter is set to either json_detail OR json_fe for the results to stay in cache.

For the `run_look` and `run_query` endpoint, the cache may be set when the result_format is set to json_detail.

This content is subject to limited support.                

Version history
Last update:
‎05-07-2021 09:48 AM
Updated by: