Prefect caching through a file target

Viewed 423

After reading the documentation on Output Caching based on a file target , I figured this workflow should be an example of output caching:

from time import sleep
from prefect import Flow, task
from prefect.engine.results import LocalResult


@task(target="func_task_target.txt", checkpoint=True, 
      result=LocalResult(dir="~/.prefect"))
def func_task():
    sleep(5)
    return 99

with Flow("Test-cache") as flow:
    func_task()

if __name__ == '__main__':
    flow.run()

I would expect func_task to run one time, get cached, and then use the cached value next time I run the flow. However, it seems that func_task runs each time.

Where am I going wrong? Or have I misunderstood the documentation?

1 Answers

Try setting environment variable PREFECT__FLOWS__CHECKPOINTING to True

import os
os.environ["PREFECT__FLOWS__CHECKPOINTING"] = "true"

you can also change the results dir

os.environ["PREFECT__HOME_DIR"] = "path to dir"
Related