Sunny Shah
11/10/2025, 6:44 AMfrom prefect.cache_policies import NO_CACHE
@task(cache_policy=NO_CACHE)
def some_task():
do_something
Is there a way to globalize the cache_policy?Marvin
11/10/2025, 6:44 AMMarvin
11/10/2025, 6:48 AMNO_CACHE is a valid cache policy and using @task(cache_policy=NO_CACHE) disables task caching for that task.
A couple of notes you may find helpful:
- Import and usage:
from prefect import task
from prefect.cache_policies import NO_CACHE
@task(cache_policy=NO_CACHE)
def my_task(...):
...
- If you also want to avoid any in-memory reuse during the same flow run and prevent result persistence, you can add:
@task(cache_policy=NO_CACHE, cache_result_in_memory=False, persist_result=False)
- cache_result_in_memory=False stops in-run memory caching.
- persist_result=False controls result storage; it’s independent of caching.
For reference:
- Caching concepts: Prefect 3.x caching concepts
- Cache policies API: prefect.cache_policies API
- Task decorator params (incl. cache options): task API reference
If your goal is to fully disable both caching and persistence for a specific task, the second example is the most explicit. Want to do this globally or just for a few tasks?