All workflows come with a session_state dictionary that you can use to cache intermediate results. The session_state is tied to a session_id and can be persisted to a database.
Provide your workflows with storage to enable persistence of session state in a database.
For example, you can use the SqliteWorkflowStorage to cache results in a Sqlite database.
Then in the run() method, you can read from and add to the session_state as needed.
When the workflow starts, the session_state for that particular session_id is read from the database and when the workflow ends, the session_state is stored in the database.
You can always call self.write_to_storage() to save the session_state to the database at any time. In case you need to abort the workflow but want to store the intermediate results.
View the Blog Post Generator for an example of how to use session state for caching.