Commit 582d5a7
committed
3.2.0 - Added MemcachedCache + privex.helpers.cache.extra, plus MUCH MORE
- **privex.helpers.settings**
- Added `DEFAULT_CACHE_ADAPTER` which can be adjusted via the env var `PRIVEX_CACHE_ADAPTER`. This setting allows
overriding the cache adapter which is used automatically by default via `cached` / `async_cached`, along with
the global adapter when you call `get_adapter`
- Added `DEFAULT_ASYNC_CACHE_ADAPTER` which can be adjusted via the env var `PRIVEX_ASYNC_CACHE_ADAPTER`.
It defaults to the same value as `DEFAULT_CACHE_ADAPTER`, since thanks to the new `import_adapter` function
and `ADAPTER_MAP` dictionary in `privex.helpers.cache`, it's now possible to reference cache adapters by simple
names such as `memcached`, `redis`, `sqlite3`, `memory` etc. - and these aliases point to either the synchronous
or asyncio version of their related adapter depending on which context they're being passed into.
- **privex.helpers.cache**
- Added `MemcachedCache` module, which contains the synchronous cache adapter `MemcachedCache`. This is simply a synchronous
version of `AsyncMemcachedCache` that uses `pylibmc` instead of `aiomcache`.
- Added `ADAPTER_MAP` dictionary, which maps aliases such as `memcached`, `redis`, `sqlite3`, `memory` etc. to their
respective synchronous and asyncio adapter module paths, which can be loaded using the
newly added `import_adapter` function, or simply using `adapter_set` / `async_adapter_set`.
- Added `import_adapter` function, which looks up an adapter alias name such as `redis` / `memcached`, maps it
to the fully qualified module path via `ADAPTER_MAP`, and then loads the module + extracts the class from the module.
- Adjusted `adapter_set`, `async_adapter_set`, along with `CacheWrapper` + `AsyncCacheWrapper` so that they now use the
default string cache adapter defined in `settings`, and can transparently handle string adapter values by passing
them off to `import_adapter`.
- Added new `extras` module
- `CacheManagerMixin` is a class mixin which adds various methods and settings to assist with class-scoped caching,
including an adjustable class-level cache prefix `.cache_prefix`, a method to remove all known cache keys managed by
your class `.clear_all_cache_keys`, and a special decorator which automatically integrates with your class `.z_cache`
by intercepting the first argument of a method call.
- `z_cache` - A special method caching decorator which is designed to integrate with classes that
extend `.CacheManagerMixin`
This is simply a wrapper for `.r_cache` - it transparently caches the output of a wrapped method/function, but
unlike `.r_cache`, it's designed to automatically integrate with classes which extend `.CacheManagerMixin` ,
allowing it to automatically retrieve cache settings such as the cache prefix, default cache time, along with
directly calling various classmethods which enable logging of newly created `cache_key` 's for painless cleanup of
cache keys when needed, without having to manually track them, or doing the nuclear option of erasing the entire
cache system's database.
- **privex.helpers.common**
- Added new small helper function `auto_list`, which is a small but useful function that simplifies the conversion
of objects into lists, sets, tuples etc. with the option to manually force a certain conversion method,
either `list wrapping` or `list iteration`
- **privex.helpers.plugin**
- Added various functions for managing **memcached instances** via the `pylibmc` library
- `connect_memcached` - create a new memcached `Client` object
- `get_memcached` - get or create a Memcached `Client` object shared by your thread
- `close_memcached` - close the Memcached `Client` connection and delete it from the threadstore
- `reset_memcached` - close the shared `Client` then re-create it again.
- `configure_memcached` - configure Memcached settings then automatically reset the shared `Client` instance.
- Added new `HAS_MEMCACHED` boolean value, to track whether synchronous memcached via `pylibmc` is available
- General stuff
- Added `pylibmc` to extras/cache.txt
- Added some missing packages to the `Pipfile` - and synchronised `Pipfile.lock`
- Added `.env` to `.gitignore`
- Created unit tests for the new `CacheManagerMixin` class and `z_cache` decorator
- Created unit tests for the new `MemcachedCache` cache adapter
- Fixed the `live` command in `docs/Makefile` for newer `sphinx-autobuild`
- Added `SqliteCache` and `MemcachedCache` to the docs
- Added `privex.helpers.cache.extras` and `privex.helpers.cache.post_dep` to the docs
- Added some other missing things to the docs
- Created and updated a lot of stub files in `privex_stubs` (assists IDEs like PyCharm with type hinting
and function/method previews)
- Possibly other various additions / fixes / improvements that I forgot to list.1 parent 8661499 commit 582d5a7
138 files changed
Lines changed: 3412 additions & 383 deletions
File tree
- docs
- source/helpers
- cache
- asyncx
- asyncsqlitecache
- extras
- extras
- cachemanagermixin
- cachesettings
- memcachedcache
- post_deps
- post_deps
- asyncsqlitecachemanager
- sqlitecachemanager
- sqlitecacheresult
- sqlitecache
- common
- extras
- privex_stubs/privex/helpers
- cache
- privex/helpers
- cache
- tests
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
3 | 84 | | |
4 | 85 | | |
5 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
37 | 42 | | |
38 | 43 | | |
39 | 44 | | |
0 commit comments