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.
- Added
-
Created new
helpers.black_magic
module for somewhat risky code that uses app introspectioncalling_function
- Returns the name of the function which called your function/method.calling_module
- Returns the name of the module which called your function/methodcaller_name
- Get the fully qualified name of a caller in the formatsome.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 toretry_on_error
, but supports wrapping asyncio coroutines
- Added
-
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 corosasyncx.AsyncRedisCache
is a new AsyncIO cache adapter for Redisasyncx.AsyncMemoryCache
is a new AsyncIO cache adapter for in-memory caching (async version ofMemoryCache
)asyncx.AsyncMemcachedCache
is a new AsyncIO cache adapter for MemcachedCacheAdapter
has a new methodget_or_set_async
, which is an async method that supports
coroutines as a value, as well as standard callable's and plain values
- Created new
-
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.
- New functions for organising __STORE by thread:
Changes / Updates
-
Added
aioredis
,hiredis
, andaiomcache
toextras/cache.txt
-
async-property
is now a core requirement, since it's used by a lot of async classes -
New settings
MEMCACHED_HOST
andMEMCACHED_PORT
for AsyncMemcachedCache -
New plugin status
HAS_ASYNC_REDIS
for detecting ifaioredis
is available -
privex.helpers.decorators
retry_on_err
has been slightly cleaned upretry_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 settinginstance_match
, which changes how exceptions are compared. When enabled, it will
compare usingisinstance()
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 correctlyawaitable
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 awith
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 intoconnect_redis
, and now usesextract_settings
for loading default settings
Testing
-
Added unit tests for
extract_settings
totests/test_general.py
-
New folders
tests/asyncx
andtests/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 newAsyncMemcachedCache
class -
tests/cache/test_async_redis.py
tests the newAsyncRedisCache
class -
tests/cache/test_async_memory.py
tests the newAsyncMemoryCache
class