Skip to main content

Caching Task Outputs

You can cache task outputs to reuse them in subsequent workflow executions. When you enable caching, the system stores the task output for a specified duration and reuses it when the same task runs again with matching input parameters. This feature can be configured in the task configuration.

Parameters

Configure the following parameters to enable task caching in your task configuration.

ParameterDescriptionRequired/ Optional
cacheConfig.keyThe cache key is a unique identifier for the cached output and must be constructed exclusively from the task’s input parameters.

It can be a string concatenation that contains the task’s input keys, such as ${uri}-${method} or re_${uri}_${method}.
Required.
cacheConfig.ttlInSecondThe time to live in seconds, which is the duration for the output to be cached.Required.

Configuration

To configure caching, add the cacheConfig object to your task configuration:

// task configuration    
"cacheConfig": {
"key": "someKey",
"ttlInSecond": "2500"
}

Task behavior with caching

Before a task is scheduled, the server checks if there is cached output for the given task definition name by matching the cache key. If a match is found, the task is not scheduled, and the cached output is used to complete it.

If no cached output is found, the task is scheduled as usual. When the task completes successfully, the output is cached under the specified cache key for the specified duration.

Enable caching in the UI

To cache task output:

  1. Go to Definitions > Workflow from the left navigation menu on your Conductor cluster.
  2. Select a workflow.
  3. In the visual workflow editor, select the task you want to cache.
  4. Turn on the Cache output toggle.
  5. Enter the Cache key and TTL (in seconds).

Configuring cache output in UI.

Example

Cache output using task input parameters

The following example shows how to cache task output using the task's input parameters url and mediaType.

// workflow definition
{
...
"tasks": [
{
"name": "get_document",
"taskReferenceName": "get_document_ref",
"inputParameters": {
"url": "${workflow.input.url}",
"mediaType": "application/pdf"
},
"type": "GET_DOCUMENT",
"cacheConfig": {
"key": "${url}-${mediaType}",
"ttlInSecond": 60
}
}
],
"inputParameters": [
"url"
],
"outputParameters": {},
"schemaVersion": 2
}

Cache output using workflow inputs

To include workflow inputs in the cache key, first pass them to the task's inputParameters. The following example passes userId from the workflow input to the task:

{
...
"tasks": [
{
"name": "get_document",
"taskReferenceName": "get_document_ref",
"inputParameters": {
"url": "${workflow.input.url}",
"mediaType": "application/pdf",
"id": "${workflow.input.userId}"
},
"type": "GET_DOCUMENT",
"cacheConfig": {
"key": "${url}-${id}",
"ttlInSecond": 60
}
}
],
"inputParameters": [
"url",
"userId"
],
"outputParameters": {},
"schemaVersion": 2
}

Cache output using variables from previous tasks

The following example shows how to use a variable from a Set Variable task in the cache key:

// workflow definition
{
...
"tasks": [
{
"name": "set_variable",
"taskReferenceName": "set_variable_ref",
"type": "SET_VARIABLE",
"inputParameters": {
"region": "${workflow.input.location}"
}
},
{
"name": "http",
"taskReferenceName": "http_ref",
"inputParameters": {
"uri": "https://orkes-api-tester.orkesconductor.com/api",
"method": "GET",
"accept": "application/json",
"contentType": "application/json",
"encode": true,
"body": {
"cacheKey": "${workflow.variables.region}",
"someUnrelated": "Some-val-qvw4g"
}
},
"type": "HTTP",
"cacheConfig": {
"key": "re_${body.cacheKey}",
"ttlInSecond": 60
}
}
],
"inputParameters": [
"location"
],
"outputParameters": {},
"schemaVersion": 2
}

Supported tasks

Caching is available for the following task types: