2.7.0 - Async cache adapters + many new functions
New Features / Additions
-
privex.helpers.common- Added
extract_settingsfor extracting prefixed settings from modules, classes or dict's.
- Added
-
Created new
helpers.black_magicmodule 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.typesmodule for holding type aliases and new type definitions -
privex.helpers.decorators- Added
async_retrydecorator, which works similar toretry_on_error, but supports wrapping asyncio coroutines
- Added
-
privex.helpers.cache- Created new
asyncxsubmodule for AsyncIO cache adapters asyncx.base.AsyncCacheAdapteris a new base class for AsyncIO cache adapters, with all methods as corosasyncx.AsyncRedisCacheis a new AsyncIO cache adapter for Redisasyncx.AsyncMemoryCacheis a new AsyncIO cache adapter for in-memory caching (async version ofMemoryCache)asyncx.AsyncMemcachedCacheis a new AsyncIO cache adapter for MemcachedCacheAdapterhas 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_asyncetc. - New functions for managing AsyncIO Memcached (aiomcache) instances
get_memcached_async,close_memcached_asyncetc.
- New functions for organising __STORE by thread:
Changes / Updates
-
Added
aioredis,hiredis, andaiomcachetoextras/cache.txt -
async-propertyis now a core requirement, since it's used by a lot of async classes -
New settings
MEMCACHED_HOSTandMEMCACHED_PORTfor AsyncMemcachedCache -
New plugin status
HAS_ASYNC_REDISfor detecting ifaioredisis available -
privex.helpers.decoratorsretry_on_errhas been slightly cleaned upretry_on_errnow supports ignoring exceptions, so you can list exceptions that cause a retry, but shouldn't increase the retry count.retry_on_errnow supports the settinginstance_match, which changes how exceptions are compared. When enabled, it will
compare usingisinstance()instead of an exact type comparison.
-
privex.helpers.asyncxawaitabledecorator now detects when it's received a non-async function, and returns the result correctlyawaitablenow supports "blacklisting" functions/modules, to ensure when those functions/modules call an@awaitablefunction,
that they always get a synchronous result, not a coroutine.
-
privex.helpers.cacheCacheWrappernow uses@awaitablefor most methods, allowing AsyncIO cache adapters to be used without breaking existing
synchronous code which uses the cache API.CacheAdapternow has dummy__enter__and__exit__methods defined, allowing all synchronous cache adapters to be used
in awithstatement, regardless of whether they actually use context management.
-
privex.helpers.pluginget_redis,close_redis,reset_redisetc. 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_settingsfor loading default settings
Testing
-
Added unit tests for
extract_settingstotests/test_general.py -
New folders
tests/asyncxandtests/cachefor containing flat test case modules using pytest-asyncio -
tests/asyncx/test_async_retry.pytests the new@async_retrydecorator -
tests/cache/test_async_memcached.pytests the newAsyncMemcachedCacheclass -
tests/cache/test_async_redis.pytests the newAsyncRedisCacheclass -
tests/cache/test_async_memory.pytests the newAsyncMemoryCacheclass