Skip to content

Commit 78b9871

Browse files
author
rodrigo.nogueira
committed
docs: document multi-loop reuse pattern via __wrapped__
1 parent 800a488 commit 78b9871

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@ instances per loop:
135135
_local.fetcher = fetch_data
136136
return _local.fetcher
137137
138+
You can also reuse the logic of an already decorated function in a new loop by accessing ``__wrapped__``:
139+
140+
.. code-block:: python
141+
142+
@alru_cache(maxsize=32)
143+
async def my_task(x):
144+
...
145+
146+
# In Loop 1:
147+
# my_task() uses the default global cache instance
148+
149+
# In Loop 2 (or a new thread):
150+
# Create a fresh cache instance for the same logic
151+
cached_task_loop2 = alru_cache(maxsize=32)(my_task.__wrapped__)
152+
await cached_task_loop2(x)
153+
138154
Benchmarks
139155
----------
140156

0 commit comments

Comments
 (0)