Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cdd9ce5

Browse files
committed
Add doc section on wire() caching
1 parent 51c7db7 commit cdd9ce5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

‎docs/wiring.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,36 @@ or with a single container ``register_loader_containers(container)`` multiple ti
631631
To unregister a container use ``unregister_loader_containers(container)``.
632632
Wiring module will uninstall the import hook when unregister last container.
633633

634+
Few notes on performance
635+
------------------------
636+
637+
``.wire()`` utilize caching to speed up the wiring process. At the end it clears the cache to avoid memory leaks.
638+
But this may not always be desirable, when you want to keep the cache for the next wiring
639+
(e.g. due to usage of multiple containers or during unit tests).
640+
641+
To keep the cache after wiring, you can set flag ``keep_cache=True`` (works with ``WiringConfiguration`` too):
642+
643+
.. code-block:: python
644+
645+
container1.wire(
646+
modules=["yourapp.module1", "yourapp.module2"],
647+
keep_cache=True,
648+
)
649+
container2.wire(
650+
modules=["yourapp.module2", "yourapp.module3"],
651+
keep_cache=True,
652+
)
653+
...
654+
655+
and then clear it manually when you need it:
656+
657+
.. code-block:: python
658+
659+
from dependency_injector.wiring import clear_cache
660+
661+
clear_cache()
662+
663+
634664
Integration with other frameworks
635665
---------------------------------
636666

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /