https://prefect.io logo
Title
r

Ross Leung

04/03/2023, 8:54 PM
Weird cache expiration behavior. I’m using
@task(cache_key_fn=task_input_hash)
so the Flow() will not execute the code inside tasks that have been completed before. I did not change the inputs to the task signature, but I did add a simple
time.sleep(10)
into my task code. I went away for 1-2 minutes and re-ran the task expecting a Cached(Completed()) status, but my task code ran again. Documentation says that unless specified, the cache never expires. So I wonder if changing the task code itself (without changing the task inputs) changes the hash?
d

Deceivious

04/04/2023, 8:38 AM
Heres a snippet of how the task input hash works. The byte code of the function (
context.task.fn.__<http://code__.co|code__.co>_code.hex(),
) is part of the "hash". I am not from prefect team or a "python pro" but I am guessing that this makes difference. If you make changes on the code, run it and then run it again. The 1st time it should create a new cache and the 2nd time it should use that cache. Atleast thats what i understand.