<@ULVA73B9P> I'm looking into custom cache key fun...
# ask-marvin
c
@Marvin I'm looking into custom cache key functions and I see that they require the TaskRunContext arg. if I'm running a script locally that uses a custom cache key function - outside the context of prefect, will it blow up?
m
When using custom cache key functions in Prefect, the function requires two arguments: the
TaskRunContext
and a dictionary of input values. The
TaskRunContext
provides task run metadata such as
task_run_id
,
flow_run_id
, and
task
. This context is only available during a task run within Prefect, so if you try to run this script locally without Prefect, it will indeed "blow up" as the
TaskRunContext
won't be available. If you want to test your cache key function locally, you could mock the
TaskRunContext
and the input dictionary, but it would require some setup to simulate the Prefect environment. For more information, you can refer to the Prefect documentation on task caching. Additionally, here's the Prefect top-level API for reference: -
flow
-
task
-
get_run_logger
-
State
-
allow_failure
-
deploy
This should help you in understanding the context in which these functions operate.