﻿# Prefect cache identity can include the flow run

Prefect cache policy can include run identity, inputs and task source; cross-run reuse needs an explicit freshness contract for external documents, model routes and other dependencies.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/guide-prefect-cache-policy-run-identity/
Language: en

## Follow a repeated classification through its key

A task classifies the same document twice during a flow and later processes it in another flow run. Prefect's current [cache-policy source](https://raw.githubusercontent.com/PrefectHQ/prefect/main/src/prefect/cache_policies.py) defines DEFAULT as a combination of inputs, task source and run identity. Including run identity makes reuse different from a global function-input memoization rule. Inspect the effective task policy before explaining why apparently identical calls did or did not reuse a result.

## Distinguish explicit cross-run reuse

An explicitly chosen policy can combine input and source identity without including the current run. That broadens the reuse scope. Decide whether the task is a stable transformation or a request for a fresh observation. For model classification, the same document identifier can point to changed text, and the same model label can route differently. Include the versioned facts the task actually depends on, or choose a refresh approach consistent with the user's requested freshness.

## Account for dependencies outside task source

The source-policy implementation considers the task's raw source, rather than recursively hashing nested tasks and every imported helper. A helper change or external configuration change can therefore matter without appearing in that component of the key. [Progressive reading](/journal/learn-codex-progressive-reading/) helps identify the actual dependency chain. Do not describe source-based caching as proof that the entire software environment and every external dataset remained equivalent.

## Separate key identity from stored availability

The [task reference](https://reference.prefect.io/prefect/tasks/) exposes cache policy, expiration, refresh and result-persistence controls. The [transaction implementation](https://raw.githubusercontent.com/PrefectHQ/prefect/main/src/prefect/transactions.py) looks for a stored record by key. Computing the same key does not independently prove an accessible reusable result exists. Storage configuration and lifecycle remain relevant, especially when several workers or environments are intended to share records.

## Make the reuse decision visible in the output

Attach the source revision and relevant generation configuration to the task's recorded result when those facts explain its meaning. A cached classification should be distinguishable from a newly requested observation if the consumer cares about freshness. [Tool observations](/journal/learn-codex-tool-observation/) separate key matching, cache use and actual execution. The goal is an explainable reuse contract: the application knows why the old result is still suitable, rather than merely observing that a cache lookup succeeded.
