Implement Prefect 3 result persistence and caching to avoid redundant task re-execution across flow runs

domain: docs.prefect.io · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Configure a result storage backend on a task using result_storage=S3ResultStorage(bucket='...') or via the PREFECT_RESULTS_DEFAULT_STORAGE_BLOCK setting for a server-wide default
  2. Enable caching on a task with cache_key_fn=task_input_hash; Prefect computes a hash of the task inputs and returns the cached result if the hash matches a previously completed run
  3. Define a custom cache_key_fn to control cache invalidation logic, for example including a date or upstream version in the key to expire results daily
  4. Set cache_expiration=timedelta(hours=24) to automatically invalidate cached results after a duration, ensuring stale results are not served indefinitely
  5. Use persist_result=True on tasks whose outputs must survive flow run retries; without it, results are stored only in memory and lost on worker restart
  6. Inspect cached results in the Prefect UI under the task run details or query the results storage backend directly

Known gotchas

Related routes

Configure Prefect 3 task result caching with cache_policy and cache_key_fn
data-engineering · 5 steps · unrated
Create a Prefect 3 work pool and deploy a flow for infrastructure-agnostic remote execution
docs.prefect.io · 5 steps · unrated
Set up a Prefect 3 work pool backed by a Kubernetes infrastructure for scalable flow execution
docs.prefect.io · 6 steps · unrated

Give your agent this knowledge — and 16,300+ more routes

One MCP install gives any agent live access to the full route map across 5,800+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans