https://prefect.io logo
Title
y

yu zeng

07/15/2022, 12:23 PM
from prefect.storage import GitHub,GitLab, S3, Webhook

from prefect.backend.artifacts import create_link_artifact
import prefect.engine.cache_validators


@task( task_run_name="mviz_task_{md5}", max_retries=0, cache_for=datetime.timedelta(hours=1),
      )
def test( md5,   ):
    print('do test', md5 )
    

with Flow("epl" ) as flow:
    test( '123' )
    test( '123' )
flow.run()
hi, i try to use cache in a single flow run, but i got the belllow output which shows that cache not work. it seems that cache will not work durning same flow run or there are some mistakes in my code ?
[2022-07-15 12:18:00+0000] INFO - prefect.FlowRunner | Beginning Flow run for 'epl'
[2022-07-15 12:18:00+0000] INFO - prefect.TaskRunner | Task 'test': Starting task run...
[2022-07-15 12:18:00+0000] WARNING - prefect.TaskRunner | Task 'test': Can't use cache because it is now invalid
do test 123
[2022-07-15 12:18:00+0000] INFO - prefect.TaskRunner | Task 'test': Finished task run for task with final state: 'Cached'
[2022-07-15 12:18:00+0000] INFO - prefect.TaskRunner | Task 'test': Starting task run...
[2022-07-15 12:18:00+0000] WARNING - prefect.TaskRunner | Task 'test': Can't use cache because it is now invalid
do test 123
[2022-07-15 12:18:00+0000] INFO - prefect.TaskRunner | Task 'test': Finished task run for task with final state: 'Cached'
[2022-07-15 12:18:00+0000] INFO - prefect.FlowRunner | Flow run SUCCESS: all reference tasks succeeded
1
a

Anna Geller

07/15/2022, 12:38 PM
can you move code blocks to the thread?
it looks like your cache did work:
Finished task run for task with final state: 'Cached'
the idea behind caching is well explained here

https://www.youtube.com/watch?v=hKcOdQD9eGQ

y

yu zeng

07/15/2022, 1:06 PM
it looks like your cache did work: ---------------- thank u anna, but why the output "do test 123" show twice? can you move code blocks to the thread? ----------------- i'd like to do that but i don't know how to move ( rarely to use slack )
a

Anna Geller

07/15/2022, 2:34 PM
that's fine then