Skip to content

2.7.0 - Async cache adapters + many new functions

Compare
Choose a tag to compare
@Someguy123 Someguy123 released this 13 Dec 09:47
· 42 commits to master since this release

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