Update cache on materialization #42968
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When an endpoint's materialization changes (due to a new version or a materialization run), the existing cache might contain stale results, leading to users seeing outdated data. The cache needs to be invalidated if it predates these updates.
Changes
_get_cache_age_for_versionto dynamically calculate the effective cache age for inline endpoints, ensuring cached results older than the current version's creation are considered stale._get_cache_age_for_materializationto set the effective cache age for materialized endpoints based on thelast_run_atof the associatedDataWarehouseSavedQuery, ensuring cached results older than the last materialization run are considered stale._execute_inline_endpointand_execute_materialized_endpointto use these dynamically calculatedcache_age_secondsduring query execution.How did you test this code?
Added new comprehensive unit tests in
products/endpoints/backend/tests/test_endpoint_materialization.py:test_cache_invalidated_on_version_change: Verifies cache invalidation when a new endpoint version is created.test_cache_invalidated_on_materialization_update: Verifies cache invalidation when a materialized table is updated.test_version_cache_age_respects_endpoint_cache_setting: Ensures version-based cache age does not exceed the endpoint's configuredcache_age_seconds.All existing and new tests pass.
Changelog: (features only) Is this feature complete?
No
Slack Thread