Commit 7935511
committed
2.16.0 - Overhaul to caching system (esp. AsyncIO), run_coro_thread function, plugin system cleanup + more
**New Additions**
- **Caching**
- Added `AsyncCacheWrapper` and `async_cached` which provide a separate cache abstraction layer
which is purely AsyncIO - to avoid event loop problems caused by the synchronous backwards
compatibility wrappers used by the standard hybrid `CacheWrapper`
- **AsyncIO**
- Added `run_coro_thread` to make running coroutines in a separate thread with a dedicated event
loop easier.
- `run_coro_thread_base` - wrapper function used by `run_coro_thread` to create the thread
- `coro_thread_func` - the function used as the target of the thread created by `run_coro_thread_base`
which creates the new event loop and runs the coroutine, emitting the result or exception back to the
caller via a threading Queue
- **Common**
- Added `LayeredContext` - a wrapper class for context manager classes / functions, which allows easily
managing multi-layer deep `with x` or `async with x` contexts for a single class instance / function,
such as the ability to consume `__enter__` / `__exit__` calls after a certain layer of `with` nesting,
and simply returning the previous layer's context - instead of duplicating context objects for every layer,
or preventing re-running entry/exit code which should only be ran for the first `with` layer.
- **Plugin**
- Added `_get_all_threadstore`, a generator function for easily iterating over the entire thread store,
or extracting a specific key from all threads in the thread store.
**Changes / Improvements**
- **Plugin**
- Added `clean_all` parameter to `clean_threadstore`, which has two operational modes, depending
on whether `name` is also specified. It allows for either cleaning a certain key from all thread ID stores,
or removing every key in all thread ID stores.
- Added `clean_all` to most connection closing / cleanup functions such as `close_redis` / `close_memcached_async`
- Added error handling when closing `aioredis` connects in `close_redis_async`
- **Caching**
- Improvements instance/connection handling within cache adapters through the addition of the new adapter interface methods
`close`, `connect` and `reconnect`.
- Improvements to context management across most cache adapters through ensuring both standard and asyncio context
manager methods are present, with the base `CacheAdapter` class automatically running `.reconnect` / `.close`
depending on a configurable class attribute and instance attribute.
- Overhaul of `CacheWrapper` to improve handling of the adapter instance, plus context tracking using
the new `LayeredContext` class - helping to prevent issues when nesting `with` / `async with` statements
when using the global cache wrappers
- Updated the decorator `r_cache_async` to access the new global AsyncIO adapter (directly instead of via wrapper),
and uses the newly improved context management to ensure no issues with cache instances attached
to other event loops / threads, or stale instances/connections.
- Various other improvements to the caching system
**Plus other small changes**1 parent ad5ae8d commit 7935511
49 files changed
Lines changed: 1413 additions & 105 deletions
File tree
- docs/source/helpers
- asyncx
- cache
- asynccachewrapper
- common
- layeredcontext
- plugin
- extras
- privex/helpers
- cache
- asyncx
- tests
- asyncx
- cache
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
docs/source/helpers/cache/asynccachewrapper/privex.helpers.cache.AsyncCacheWrapper.get_adapter.rst
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
docs/source/helpers/cache/asynccachewrapper/privex.helpers.cache.AsyncCacheWrapper.set_adapter.rst
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
0 commit comments