persist_for

LookML
Version

On this Page
Docs Menu

Go to Model Parameter List

This page refers to the persist_for parameter that is part of a model

persist_for can also be used as part of an explore, described here

persist_for can also be used as part of a derived table, described here

Usage

- persist_for: 5 hours
an integer followed
by a timeframe:
n seconds
n minutes
n hours

Definition

Consider instead using datagroups with persist_with, as described on this page about caching.

persist_for enables you to modify the amount of time that cached query results are used for a given explore. The default cache length in Looker is 1 hour. Cache results are stored in an encrypted file on your Looker instance.

The caching mechanism in Looker works as follows: once a user runs a specific query, the result of that query is cached. If someone runs precisely the same query again (everything must be the same, including minor things such as the row limit) in less than the time period specified by persist_for, then the cached results are returned. Otherwise, a new query is run against your database.

If persist_for is set for both a model and one of its explores, the value set for the explore will take priority for queries based on that explore.

Seeing Whether a Query Was Returned From Cache

You can determine whether or not a query has been returned from the cache by looking in the upper right corner after running a query.

If results are from a fresh query,
you will see …
If the results are from the cache,
you will see …

Forcing New Results To Be Generated From the Database

You can force new results to be generated by selecting the Clear Cache & Refresh option from the Gear dropdown menu, which you’ll find in the upper right of the screen after running a query:

Examples

Adjust the cache length to 2 hours:

- persist_for: 2 hours

Adjust the cache length to 30 minutes:

- persist_for: 30 minutes

Turn off caching:

- persist_for: 0 seconds

Common Challenges

persist_for Does Not Necessarily Align With Your Data Import

Many companies have a daily data import to their analytics database. Sometimes, they reason that there is no purpose running fresh queries if the data isn’t constantly updated anyway, so they set the cache length to 24 hours (like persist_for: 24 hours). However, this will not prevent users from getting data that is older than the most recent refresh.

For example, suppose a query is run at noon on January 1st, new data is imported the morning of January 2nd, and then the query is run again at noon on January 2nd. Since the query was run within the 24 hour window specified by persist_for, the data from January 1st will be returned, even though new data was loaded on January 2nd.

If you want your caching to be aligned with data imports, use datagroups with persist_with.

Scheduled Looks Will Cache Results

When a scheduled Look is run, it will create a cached result set in the same way that a user run query would. If you want to pre-cache a certain report, you may want to consider saving and scheduling it.

Still have questions?
Go to Discourse - or - Email Support
Top