-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
async_simple_cache_middleware
- Add async support for simple cache middleware - Refactor ``SessionCache`` as a more generic ``SimpleCache`` class to be used internally as a standardized cache where appropriate. - Use ``SimpleCache`` as the default cache for the simple cache middleware
- Loading branch information
Showing
10 changed files
with
418 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Async support for caching certain methods via ``async_simple_cache_middleware`` as well as constructing custom async caching middleware via ``async_construct_simple_cache_middleware``. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import asyncio | ||
from concurrent.futures import ( | ||
ThreadPoolExecutor, | ||
) | ||
import contextlib | ||
import threading | ||
from typing import ( | ||
AsyncGenerator, | ||
) | ||
|
||
|
||
@contextlib.asynccontextmanager | ||
async def async_lock( | ||
pool: ThreadPoolExecutor, lock: threading.Lock | ||
) -> AsyncGenerator[None, None]: | ||
loop = asyncio.get_event_loop() | ||
await loop.run_in_executor(pool, lock.acquire) | ||
try: | ||
yield | ||
finally: | ||
lock.release() |
Oops, something went wrong.