Skip to content

Commit 7935511

Browse files
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

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 numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
coro\_thread\_func
2+
==================
3+
4+
.. currentmodule:: privex.helpers.asyncx
5+
6+
.. autofunction:: coro_thread_func
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
run\_coro\_thread
2+
=================
3+
4+
.. currentmodule:: privex.helpers.asyncx
5+
6+
.. autofunction:: run_coro_thread
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
run\_coro\_thread\_base
2+
=======================
3+
4+
.. currentmodule:: privex.helpers.asyncx
5+
6+
.. autofunction:: run_coro_thread_base
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cache\_instance
2+
===============
3+
4+
.. currentmodule:: privex.helpers.cache
5+
6+
.. autoattribute:: AsyncCacheWrapper.cache_instance
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
get\_adapter
2+
============
3+
4+
.. currentmodule:: privex.helpers.cache
5+
6+
.. automethod:: AsyncCacheWrapper.get_adapter
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
instance\_args
2+
==============
3+
4+
.. currentmodule:: privex.helpers.cache
5+
6+
.. autoattribute:: AsyncCacheWrapper.instance_args
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
instance\_kwargs
2+
================
3+
4+
.. currentmodule:: privex.helpers.cache
5+
6+
.. autoattribute:: AsyncCacheWrapper.instance_kwargs
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
max\_context\_layers
2+
====================
3+
4+
.. currentmodule:: privex.helpers.cache
5+
6+
.. autoattribute:: AsyncCacheWrapper.max_context_layers
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
reset\_adapter
2+
==============
3+
4+
.. currentmodule:: privex.helpers.cache
5+
6+
.. automethod:: AsyncCacheWrapper.reset_adapter
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
set\_adapter
2+
============
3+
4+
.. currentmodule:: privex.helpers.cache
5+
6+
.. automethod:: AsyncCacheWrapper.set_adapter

0 commit comments

Comments
 (0)