DataLens caches query results from data sources to accelerate chart and dashboard rendering. By default, the cache refreshes only after its TTL expires. This may become a constraint if you need real-time visibility, as your data will update regularly but infrequently.
Here is how cache invalidation solves this issue: the system runs an occasional invalidation query against the data source to check if the data has changed. If the query returns a different result, the cache refreshes immediately without waiting for TTL expiration.
The invalidation query must be optimized to run fast on the target database.
The system runs the invalidation query at a configured interval (throttling), while the primary data query runs only when data actually changes or the cache TTL expires:
The user configures the invalidation query in the dataset using either SQL or a formula with filters. You can only define one such query for a dataset, provided the dataset has been saved at least once.
Upon each data query, the system checks the invalidation cache first.
If the invalidation cache is stale, i.e., the throttling interval has elapsed, the system runs the invalidation query against the database.
The query returns a short string, such as "2024-01-15T10:30:00".
This result is appended to the key of the main data cache.
When the query returns a different output or the cache TTL expires, the cache key changes, and fresh data is fetched.
Throttling defines the minimum interval (N seconds) between invalidation queries. For example, with a value of 60, the query runs at most once per minute, even if the data is queried 1 000 times within that window. Until this interval elapses, subsequent queries reuse the cached invalidation query result.
Formula: The user defines a DataLens formula (same as with calculated fields) and optional filters. The system compiles and executes the formula through the standard DataLens query pipeline.
The Formula mode is convenient because it leverages native DataLens tools (formulas and filters), so you do not need to know the SQL dialect of your specific database.
In your dataset's connection settings, go to Caching settings, enable Allow cache validation in datasets and set the cache refresh interval: max everyNseconds. Acceptable values range from 30 to 86 400 seconds.
Note
For the SQL invalidation mode, enable Raw SQL level.
Open the dataset you want to configure cache validation for.
Go to the Cache validation tab.
Select an invalidation mode and configure validation settings:
None
Formula
SQL
No invalidation. The cache refreshes only upon TTL expiration. This is the default behavior.
Next to the Formula field, click Add and enter a DataLens formula following these requirements:
Invalidation query testing does not affect the main cache and ignores throttling. It is intended strictly for debugging to verify that the query runs correctly and returns the expected result.
This feature is only available to users with edit permissions for the workbook to prevent data leakage via RLS.
Viewing the last validation result does not trigger new database queries. The available data includes the most recent query output and query timestamp.
This option is only available to users with edit permissions for the workbook.
The result may be either the returned string or an execution error. An error may also indicate an empty result, e.g., if the throttling interval has elapsed but the query has not run.
To view the last validation result:
Open the dataset you want to test.
Go to the Cache validation tab. Next to the Last result field, you can see the date and time of the most recent check. If the check failed, you will see Failed with error next to Last result.
Click Open to view the check result, or Show error to see the error message.
The invalidation system follows the graceful degradation design principle: invalidation errors never block main data queries.
If invalidation is misconfigured, charts and dashboards will continue to render normally, and the cache will refresh based on its TTL as if invalidation is disabled. Error indicators will flag the affected charts and datasets, and full error details will be available in the Last result dataset field.