Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 1.31 KB

caching.md

File metadata and controls

30 lines (21 loc) · 1.31 KB

Dependency Caching

Xpresso has a dependency caching system. This allows re-using of already computed dependencies within a request response cycle. This is also what enables Xpresso to persist "app" scoped dependencies across requests (see Scopes). By default, all dependencies are cached within their execution scope, but this can be disabled on a per-dependency basis with the use_cache argument to Depends.

First we are going to declare a placeholder dependency with no sub-dependencies. We are just going to compare instances, so there's nothing else needed in this dependency.

--8<-- "docs_src/advanced/dependencies/tutorial_003.py"

Next we'll create two dependencies that depend on this dependency to test that sub-dependencies are shared:

--8<-- "docs_src/advanced/dependencies/tutorial_003.py"

Finally we create an endpoint that checks that the shared sub-dependencies are the same but the dependency declared with use_cache=False is not the same:

--8<-- "docs_src/advanced/dependencies/tutorial_003.py"

You can test this by running the app and navigating to http://127.0.0.1:800/shared. You should get a 200 OK response with no errors.