Server-side caching
Return cached results when re-executing tasks
The Airplane API can optionally return a cached result when a task is executed instead of re-running
the task. This feature is useful for non-mutating tasks that are expensive to run and/or accessed in
performance-sensitive settings like views.
Task configuration
Task configuration
To allow runs of a particular task to return cached results by default, set the
allowCachedMaxAge
or allow_cached_max_age field in the task definition to a number of seconds between 0 and
172800, inclusive:typescriptCopied1export default airplane.task(2{3slug: "task_with_caching",4name: "Task with caching",5allowCachedMaxAge: 600,6}),7async (params) => {8// Task code9},
pythonCopied1@airplane.task(2slug="task_with_caching",3name="Task with caching",4allow_cached_max_age=600,5)6def task_with_caching():7# Task code
yamlCopied1slug: task_with_caching2name: Task with caching34allowCachedMaxAge: 60056# Rest of task definition
When this task is executed by an Airplane SDK or view query, the Airplane API will look for a recent
run with the same inputs that successfully finished no more than the max age ago. If such a run is
found, then the API will return that run ID to the client instead of creating a new task run. See
the Cachability section below for more details on this process.
Setting the max age to
0 effectively disables caching (which is the default behavior if this field
isn't specified), whereas larger values allow for increasingly older runs to be used. The optimal
number to set here will depend on the specific freshness vs. performance tradeoffs for the users of
the task. To be safe, it's probably best to start low (e.g., 600) and then increase this value
after more testing.Client configuration
Client configuration
The Airplane JavaScript and Python SDKs allow overriding the value of the cache max age for a
particular task execution. Setting this value to
0, for instance, allows a client to turn off
caching even if it's configured in the task definition:typescriptCopied1export default airplane.task(2{3slug: "task_with_cache_override",4}),5async (params) => {6const result = await airplane.execute(7"my_other_task",8{ nameParam: "my name" },9{ allowCachedMaxAge: 0 },10);11},
pythonCopied1@airplane.task(slug="task_with_cache_override")2def task_with_cache_override():3result = airplane.execute(4"my_other_task",5{"nameParam": "my name"},6allow_cached_max_age=0,7)
Similarly, this value can be overriden for queries made by task-backed view components. See the
views documentation for more details.
Cachability
Cachability
All task runs can serve as cache sources, but only executions from an Airplane SDK or view query
will possibly return a cached result. In particular, this means that clicking the "Execute" button
in the Airplane UI will always trigger a new run, although it's possible for child runs called by
this one to use cached results.
When matching an eligible execution request to previous runs, the Airplane API will pick the most
recent, successful run within the max age window that matches on all of the following dimensions:
- Run parameter values
- Run constraint values
- Run Airplane environment
- Run inputs zone (if using self-hosted inputs)
- Task slug and version
If such a run is found and the executor has permissions to see it, then the API will return the
cached run to the client. Otherwise, a new run will be created and the API will return that one
instead.