Skip to content

Commit d469dd3

Browse files
committed
2.7.0 - Async cache adapters + many new functions
**New Features / Additions** - `privex.helpers.common` - Added `extract_settings` for extracting prefixed settings from modules, classes or dict's. - Created new `helpers.black_magic` module for *somewhat risky* code that uses app introspection - `calling_function` - Returns the name of the function which called your function/method. - `calling_module` - Returns the name of the module which called your function/method - `caller_name` - Get the fully qualified name of a caller in the format `some.module.SomeClass.method` - Created new `helpers.types` module for holding type aliases and new type definitions - `privex.helpers.decorators` - Added `async_retry` decorator, which works similar to `retry_on_error`, but supports wrapping asyncio coroutines - `privex.helpers.cache` - Created new `asyncx` submodule for AsyncIO cache adapters - `asyncx.base.AsyncCacheAdapter` is a new base class for AsyncIO cache adapters, with all methods as coros - `asyncx.AsyncRedisCache` is a new AsyncIO cache adapter for Redis - `asyncx.AsyncMemoryCache` is a new AsyncIO cache adapter for in-memory caching (async version of `MemoryCache`) - `asyncx.AsyncMemcachedCache` is a new AsyncIO cache adapter for Memcached - `CacheAdapter` has a new method `get_or_set_async`, which is an async method that supports coroutines as a value, as well as standard callable's and plain values - `privex.helpers.plugin` - New functions for organising __STORE by thread: `_get_threadstore`, `_set_threadstore`, `clean_threadstore` - New functions for managing AsyncIO Redis (aioredis) instances `get_redis_async`, `close_redis_async` etc. - New functions for managing AsyncIO Memcached (aiomcache) instances `get_memcached_async`, `close_memcached_async` etc. **Changes / Updates** - Added `aioredis`, `hiredis`, and `aiomcache` to `extras/cache.txt` - `async-property` is now a core requirement, since it's used by a lot of async classes - New settings `MEMCACHED_HOST` and `MEMCACHED_PORT` for AsyncMemcachedCache - New plugin status `HAS_ASYNC_REDIS` for detecting if `aioredis` is available - `privex.helpers.decorators` - `retry_on_err` has been slightly cleaned up - `retry_on_err` now supports **ignoring exceptions**, so you can list exceptions that cause a retry, but shouldn't increase the retry count. - `retry_on_err` now supports the setting `instance_match`, which changes how exceptions are compared. When enabled, it will compare using `isinstance()` instead of an exact type comparison. - `privex.helpers.asyncx` - `awaitable` decorator now detects when it's received a non-async function, and returns the result correctly - `awaitable` now supports "blacklisting" functions/modules, to ensure when those functions/modules call an `@awaitable` function, that they always get a synchronous result, not a coroutine. - `privex.helpers.cache` - `CacheWrapper` now uses `@awaitable` for most methods, allowing AsyncIO cache adapters to be used without breaking existing synchronous code which uses the cache API. - `CacheAdapter` now has dummy `__enter__` and `__exit__` methods defined, allowing all synchronous cache adapters to be used in a `with` statement, regardless of whether they actually use context management. - `privex.helpers.plugin` - `get_redis`, `close_redis`, `reset_redis` etc. now use the new thread store system to help ensure thread safety by separating instances per thread. - Refactored `get_redis`'s connection opening into `connect_redis`, and now uses `extract_settings` for loading default settings **Testing** - Added unit tests for `extract_settings` to `tests/test_general.py` - New folders `tests/asyncx` and `tests/cache` for containing flat test case modules using pytest-asyncio - `tests/asyncx/test_async_retry.py` tests the new `@async_retry` decorator - `tests/cache/test_async_memcached.py` tests the new `AsyncMemcachedCache` class - `tests/cache/test_async_redis.py` tests the new `AsyncRedisCache` class - `tests/cache/test_async_memory.py` tests the new `AsyncMemoryCache` class Additional merged commits: - enable memcached on travis
1 parent 93a081d commit d469dd3

File tree

75 files changed

+2750
-73
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2750
-73
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
dist: bionic
22
services:
33
- redis-server
4+
- memcached
45
language: python
56
cache: pip
67
python:

Pipfile

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ verify_ssl = true
66
[dev-packages]
77
pytest = "*"
88
pytest-cov = "*"
9+
pytest-asyncio = "*"
910
coverage = "*"
1011
codecov = "*"
1112
twine = "*"
@@ -28,6 +29,10 @@ MarkupSafe = ">=1.1.1"
2829
wheel = "*"
2930
python-dateutil = "*"
3031
sniffio = "*"
32+
aioredis = "*"
33+
async-property = "*"
34+
aiomcache = "*"
35+
hiredis = "*"
3136

3237
[requires]
3338
python_version = "3.8"

Pipfile.lock

+107-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
caller\_name
2+
============
3+
4+
.. currentmodule:: privex.helpers.black_magic
5+
6+
.. autofunction:: caller_name
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
calling\_function
2+
=================
3+
4+
.. currentmodule:: privex.helpers.black_magic
5+
6+
.. autofunction:: calling_function
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
calling\_module
2+
===============
3+
4+
.. currentmodule:: privex.helpers.black_magic
5+
6+
.. autofunction:: calling_module
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
last\_frames
2+
============
3+
4+
.. currentmodule:: privex.helpers.black_magic
5+
6+
.. autofunction:: last_frames
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
last\_stack\_frame
2+
==================
3+
4+
.. currentmodule:: privex.helpers.black_magic
5+
6+
.. autofunction:: last_stack_frame
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
\_\_init\_\_
2+
============
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncMemcachedCache
5+
6+
.. automethod:: AsyncMemcachedCache.__init__
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
get
2+
===
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncMemcachedCache
5+
6+
.. automethod:: AsyncMemcachedCache.get
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
mcache
2+
======
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncMemcachedCache
5+
6+
.. autoattribute:: AsyncMemcachedCache.mcache
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pickle\_default
2+
===============
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncMemcachedCache
5+
6+
.. autoattribute:: AsyncMemcachedCache.pickle_default
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
remove
2+
======
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncMemcachedCache
5+
6+
.. automethod:: AsyncMemcachedCache.remove
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
set
2+
===
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncMemcachedCache
5+
6+
.. automethod:: AsyncMemcachedCache.set
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
update\_timeout
2+
===============
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncMemcachedCache
5+
6+
.. automethod:: AsyncMemcachedCache.update_timeout
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
get
2+
===
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncMemoryCache
5+
6+
.. automethod:: AsyncMemoryCache.get
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
remove
2+
======
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncMemoryCache
5+
6+
.. automethod:: AsyncMemoryCache.remove
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
set
2+
===
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncMemoryCache
5+
6+
.. automethod:: AsyncMemoryCache.set
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
update\_timeout
2+
===============
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncMemoryCache
5+
6+
.. automethod:: AsyncMemoryCache.update_timeout
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
\_\_init\_\_
2+
============
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncRedisCache
5+
6+
.. automethod:: AsyncRedisCache.__init__
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
get
2+
===
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncRedisCache
5+
6+
.. automethod:: AsyncRedisCache.get
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pickle\_default
2+
===============
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncRedisCache
5+
6+
.. autoattribute:: AsyncRedisCache.pickle_default
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
redis
2+
=====
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncRedisCache
5+
6+
.. autoattribute:: AsyncRedisCache.redis
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
remove
2+
======
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncRedisCache
5+
6+
.. automethod:: AsyncRedisCache.remove
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
set
2+
===
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncRedisCache
5+
6+
.. automethod:: AsyncRedisCache.set
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
update\_timeout
2+
===============
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.AsyncRedisCache
5+
6+
.. automethod:: AsyncRedisCache.update_timeout
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
get
2+
===
3+
4+
.. currentmodule:: privex.helpers.cache.asyncx.base
5+
6+
.. automethod:: AsyncCacheAdapter.get

0 commit comments

Comments
 (0)