How can I cache a task result based on task input arguments?

Prefect 2.0

You can set the cache_key_fn argument to task_input_hash.

from prefect import task
from prefect.tasks import task_input_hash

@task(cache_key_fn=task_input_hash)
def my_task():
    pass

Prefect 1.0

Prefect 1.0 provides a cache_validator argument that can be set to all_inputs or partial_inputs_only.

from prefect import task

@task(cache_validator=prefect.engine.cache_validators.all_inputs)
def my_task():
    ...

See also: