Commit d469dd3
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 travis1 parent 93a081d commit d469dd3
File tree
75 files changed
+2750
-73
lines changed- docs/source/helpers
- black_magic
- cache
- asyncmemcachedcache
- asyncmemorycache
- asyncrediscache
- base
- asynccacheadapter
- cachewrapper
- common
- decorators
- extras
- privex/helpers
- cache
- asyncx
- tests
- asyncx
- cache
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| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
31 | 36 | | |
32 | 37 | | |
33 | 38 | | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
0 commit comments