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.

Supported tasks

Caching is available for the following task types:

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 hit

Run the following workflow twice with the same input. The second run returns the cached result.

To create and run workflow from Conductor UI:

  1. Go to Definitions > Workflow from the left navigation menu on your Conductor UI.
  2. Select + Define workflow and paste the following code in the Code tab:
{
"name": "cache_basic_example",
"description": "Basic task output caching example",
"version": 1,
"tasks": [
{
"name": "http_poll",
"taskReferenceName": "http_poll_ref",
"type": "HTTP_POLL",
"inputParameters": {
"uri": "https://orkes-api-tester.orkesconductor.com/api",
"method": "GET",
"accept": "application/json",
"contentType": "application/json",
"terminationCondition": "true",
"env": "${workflow.input.env}"
},
"cacheConfig": {
"key": "${env}",
"ttlInSecond": 120
}
}
],
"inputParameters": ["env"],
"outputParameters": {},
"schemaVersion": 2
}
  1. Go to the Run tab and run the workflow using the following input:
{
"env": "prod"
}
  • For the first execution (cache miss): The task executes the API call, and the pollCount is 1. The result is stored in cache under key prod for 120 seconds.
  • For the second execution with the same input (cache hit): The cached result is returned immediately without executing the task. The task output includes _cachedResponse: true and pollCount is 0.

Example for cache hit

Cache miss

Run the workflow with a different input. A different cache key is computed, so no cached result is found and the task executes fresh.

Use the same workflow definition as Cache hit example. First run with input as “env”:”prod” and then run using a different input:

{
"env": "staging"
}

The cache key now resolves to staging, which has no cached entry. The task executes the API call. pollCount is 1 and there is no _cachedResponse in the output.

Example for cache miss

Each unique cache key has its own independent cache entry. Running with env: "prod" and env: "staging" are treated as separate executions.

Cache expiry (TTL)

When the TTL expires, the cached result is discarded and the next run executes the task fresh.

To create and run workflow from Conductor UI:

  1. Go to Definitions > Workflow from the left navigation menu on your Conductor UI.
  2. Select + Define workflow and paste the following code in the Code tab:
{
"name": "cache_ttl_example",
"description": "Demonstrates cache expiry using a short TTL",
"version": 1,
"tasks": [
{
"name": "http_poll",
"taskReferenceName": "http_poll_ref",
"type": "HTTP_POLL",
"inputParameters": {
"uri": "https://orkes-api-tester.orkesconductor.com/api",
"method": "GET",
"accept": "application/json",
"contentType": "application/json",
"terminationCondition": "true"
},
"cacheConfig": {
"key": "ttl_test_key",
"ttlInSecond": 30
}
}
],
"inputParameters": [],
"outputParameters": {},
"schemaVersion": 2
}
  1. Run the workflow once and then a second time immediately.
  2. Wait for 30 seconds and run for a third time.

For the first execution: Task executes the API call. The result is cached for 30 seconds, and the pollCount is 1.

Example for cache TTL expiry

For the second execution within 30 seconds (cache hit): Cached result is returned. _cachedResponse: true and the pollCount is 0.

Example for cache TTL expiry

For the third execution after 30 seconds (cache miss): The cache entry has expired. The task executes the API call again. pollCount is 1 and there is no _cachedResponse.

Example for cache TTL expiry

Cache output using task input parameters

Cache the task output based on a value passed directly in the task's inputParameters. Here, the method field is used as part of the cache key, so GET and POST requests are cached separately.

To create and run workflow from Conductor UI:

  1. Go to Definitions > Workflow from the left navigation menu on your Conductor UI.
  2. Select + Define workflow and paste the following code in the Code tab:
{
"name": "cache_task_input_example",
"description": "Demonstrates caching task output using task input parameters",
"version": 1,
"tasks": [
{
"name": "http_poll",
"taskReferenceName": "http_poll_ref",
"type": "HTTP_POLL",
"inputParameters": {
"uri": "https://orkes-api-tester.orkesconductor.com/api",
"method": "${workflow.input.method}",
"accept": "application/json",
"contentType": "application/json",
"terminationCondition": "true"
},
"cacheConfig": {
"key": "api_${method}",
"ttlInSecond": 120
}
}
],
"inputParameters": ["method"],
"outputParameters": {},
"schemaVersion": 2
}
  1. Go to the Run tab and run the workflow once and then a second time immediately using the following input:
{
"method": "GET"
}

For the first execution (cache miss): The cache key resolves to api_GET. No cached entry exists. The task executes the API call. pollCount is 1.

Example for cache task input

For the second execution with the same input (cache hit): The cache key resolves to api_GET again. The cached result is returned immediately.

Example for cache task input

Running with "method": "POST" computes the key api_POST — a cache miss. GET and POST results are cached independently.

Cache output using workflow inputs

Cache the task output based on a workflow-level input. Each unique input value gets its own cache entry.

  1. Go to Definitions > Workflow from the left navigation menu on your Conductor UI.
  2. Select + Define workflow and paste the following code in the Code tab:
{
"name": "cache_workflow_input_example",
"description": "Demonstrates caching task output using workflow input parameters",
"version": 1,
"tasks": [
{
"name": "http_poll",
"taskReferenceName": "http_poll_ref",
"type": "HTTP_POLL",
"inputParameters": {
"uri": "https://orkes-api-tester.orkesconductor.com/api",
"method": "GET",
"accept": "application/json",
"contentType": "application/json",
"terminationCondition": "true",
"userId": "${workflow.input.userId}"
},
"cacheConfig": {
"key": "user_${userId}",
"ttlInSecond": 120
}
}
],
"inputParameters": ["userId"],
"outputParameters": {},
"schemaVersion": 2
}
  1. Go to the Run tab and run the workflow once and then a second time immediately using the following input:
{
"userId": "user-123"
}

For the first execution (cache miss): The cache key resolves to user_user-123. No cached entry exists. The task executes the API call, and the pollCount is 1.

Example for cache workflow input

For the second execution with the same userId (cache hit): The cache key resolves to user_user-123 again. The cached result is returned immediately.

Example for cache workflow input

Running with another workflow input is a cache miss. Each user ID has its own independent cache entry.

Cache output using variables from previous tasks

Cache the task output based on a value set by an earlier task in the workflow. The Set Variable task captures the input and stores it as a workflow variable, which is then referenced in the cache key.

  1. Go to Definitions > Workflow from the left navigation menu on your Conductor UI.
  2. Select + Define workflow and paste the following code in the Code tab:
{
"name": "cache_variable_example",
"description": "Demonstrates caching task output using variables from a previous task",
"version": 1,
"tasks": [
{
"name": "set_variable",
"taskReferenceName": "set_variable_ref",
"type": "SET_VARIABLE",
"inputParameters": {
"region": "${workflow.input.location}"
}
},
{
"name": "http_poll",
"taskReferenceName": "http_poll_ref",
"type": "HTTP_POLL",
"inputParameters": {
"uri": "https://orkes-api-tester.orkesconductor.com/api",
"method": "GET",
"accept": "application/json",
"contentType": "application/json",
"terminationCondition": "true",
"cacheKey": "${workflow.variables.region}"
},
"cacheConfig": {
"key": "re_${cacheKey}",
"ttlInSecond": 120
}
}
],
"inputParameters": ["location"],
"outputParameters": {},
"schemaVersion": 2
}
  1. Go to the Run tab and run the workflow once and then a second time immediately using the following input:
{
"location": "us-east-1"
}

For the first execution (cache miss): The Set Variable task runs first and stores us-east-1 as the workflow variable region. The HTTP Poll task resolves ${workflow.variables.region} to us-east-1 and computes the cache key re_us-east-1. No cached entry exists. The task executes the API call. pollCount is 1.

Example for cache variable

For the second execution with the same location (cache hit): The cache key resolves to re_us-east-1 again. The cached result is returned immediately.

Example for cache variable

Running with another workflow input is a cache miss. Each region has its own independent cache entry.