Ihor Ramskyi
08/05/2025, 4:46 PMMarvin
08/05/2025, 4:46 PMMarvin
08/05/2025, 4:47 PMbash
PREFECT_TASKS_REFRESH_CACHE=true
This will force all tasks to refresh their cache unless explicitly disabled.
2. Per-Task Cache Control
You can control caching behavior at the task level:
python
from prefect import task
@task(refresh_cache=True) # Forces cache refresh for this specific task
def my_task():
return "result"
3. Cache Policy Configuration
You can configure more detailed cache policies using the CachePolicy or CacheKeyFnPolicy classes, which allow you to specify:
- Cache storage location
- Isolation levels
- Expiration times
For example:
python
from prefect import task
from datetime import timedelta
@task(
cache_key_fn=task_input_hash,
cache_expiration=timedelta(hours=1) # Cache expires after 1 hour
)
def my_task():
return "result"
It's worth noting that while you can't directly "remove" cache entries for specific task runs, you can:
1. Force cache refresh using the methods above
2. Set short cache expiration times
3. Use different cache keys to create new cache entries
Links for more information:
- Caching Workflow Steps Guide
- Caching Concepts Documentation
Would you like me to provide more specific examples for any of these approaches?