Overview
The cache feature enables workflows to store intermediate task results, enhancing efficiency and reducing redundant computations.Configuration
- Configure caching at task level using the
cacheproperty. - Enable caching with the
enabledfield. - Specify the cache location with the
pathfield. Jinja templates can be used to dynamically generate paths. - The cache format can be
sqlorjson, depending on the task type (whether it generates SQL or JSON output - JSON is commonly used for structured output from the agent).
Core Components
| Field | Description | Required |
|---|---|---|
| enabled | Boolean to enable or disable caching | Yes |
| path | File path for cached results | Yes |
Example
Referencing Cached Queries
You can cache generated queries in workflows and reference them in subsequent tasks using Jinja. For example:- The
reporttask generates a query and caches it inoutput/agent.sql. - The
metricsloop references the cached query in theexecute_sqltask.
Benefits
- Efficiency: Saves time by reusing cached results.
- Reusability: Cached data persists across runs.
- Debugging: Provides snapshots of intermediate outputs.
- Task Interoperability: Cached queries can be referenced in subsequent tasks, enabling seamless integration between tasks.
Best Practices
- Use descriptive, unique paths to avoid conflicts.
- Include the workflow name or a unique identifier as part of the cache file path to ensure clarity and avoid overwrites.
- Regularly clean up outdated cache files.
- Validate cached results for consistency.
- Add the cache folder to
.gitignoreto avoid committing cached files.