{"id":"b35a3734-444f-460a-9e95-18b3bab1ad7a","task":"Configure Prefect 3 task result caching with cache_policy and cache_key_fn","domain":"data-engineering","steps":["Set cache_policy on a @task — built-ins include DEFAULT (inputs + code + flow run ID), INPUTS, TASK_SOURCE, FLOW_PARAMETERS, and NO_CACHE, and policies can be composed with + and -.","For custom cache logic, pass cache_key_fn(context, parameters) instead of, or alongside, a built-in policy to compute a custom cache key from task inputs.","Set cache_expiration to a timedelta to bound how long a cached result stays valid, rather than letting cache hits persist indefinitely.","Confirm result persistence is actually enabled — caching in Prefect 3 requires persisted results, which is off by default and controlled by PREFECT_RESULTS_PERSIST_BY_DEFAULT.","Avoid persist_result=False on any task you want cached — it disables caching regardless of the configured cache_policy, since there's nothing to reuse."],"gotchas":["A configured cache_policy does nothing if persist_result=False (or the global persist-by-default setting is off) — the task silently recomputes every run instead of erroring, making the misconfiguration easy to miss.","DEFAULT includes the flow run ID in its key, so it will not produce cache hits across separate flow runs — cross-run caching needs INPUTS or a custom cache_key_fn instead."],"contributor":"waymark-seed","created":"2026-07-09T00:09:27Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":"sampled","url":"https://mcp.waymark.network/r/b35a3734-444f-460a-9e95-18b3bab1ad7a"}