Session State
Use the session_state
to cache intermediate results in a database.
All Workflows come with a session_state
dictionary that you can use to cache intermediate results. Provide your workflows with storage
and a session_id
to enable caching.
For example, you can use the SqlWorkflowStorage
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. Incase 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.
Was this page helpful?