3.2.0 - Added MemcachedCache + privex.helpers.cache.extra, plus various other additions
Latest-
privex.helpers.settings
-
Added
DEFAULT_CACHE_ADAPTER
which can be adjusted via the env varPRIVEX_CACHE_ADAPTER
. This setting allows overriding the cache adapter which is used automatically by default viacached
/async_cached
, along with the global adapter when you callget_adapter
-
Added
DEFAULT_ASYNC_CACHE_ADAPTER
which can be adjusted via the env varPRIVEX_ASYNC_CACHE_ADAPTER
.It defaults to the same value as
DEFAULT_CACHE_ADAPTER
, since thanks to the newimport_adapter
function andADAPTER_MAP
dictionary inprivex.helpers.cache
, it's now possible to reference cache adapters by simple names such asmemcached
,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 adapterMemcachedCache
. This is simply a synchronous version ofAsyncMemcachedCache
that usespylibmc
instead ofaiomcache
. -
Added
ADAPTER_MAP
dictionary, which maps aliases such asmemcached
,redis
,sqlite3
,memory
etc. to their respective synchronous and asyncio adapter module paths, which can be loaded using the newly addedimport_adapter
function, or simply usingadapter_set
/async_adapter_set
. -
Added
import_adapter
function, which looks up an adapter alias name such asredis
/memcached
, maps it to the fully qualified module path viaADAPTER_MAP
, and then loads the module + extracts the class from the module. -
Adjusted
adapter_set
,async_adapter_set
, along withCacheWrapper
+AsyncCacheWrapper
so that they now use the default string cache adapter defined insettings
, and can transparently handle string adapter values by passing them off toimport_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 createdcache_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, eitherlist wrapping
orlist iteration
- Added new small helper function
-
privex.helpers.plugin
- Added various functions for managing memcached instances via the
pylibmc
libraryconnect_memcached
- create a new memcachedClient
objectget_memcached
- get or create a MemcachedClient
object shared by your threadclose_memcached
- close the MemcachedClient
connection and delete it from the threadstorereset_memcached
- close the sharedClient
then re-create it again.configure_memcached
- configure Memcached settings then automatically reset the sharedClient
instance.
- Added new
HAS_MEMCACHED
boolean value, to track whether synchronous memcached viapylibmc
is available
- Added various functions for managing memcached instances via the
-
General stuff
- Added
pylibmc
to extras/cache.txt - Added some missing packages to the
Pipfile
- and synchronisedPipfile.lock
- Added
.env
to.gitignore
- Created unit tests for the new
CacheManagerMixin
class andz_cache
decorator - Created unit tests for the new
MemcachedCache
cache adapter - Fixed the
live
command indocs/Makefile
for newersphinx-autobuild
- Added
SqliteCache
andMemcachedCache
to the docs - Added
privex.helpers.cache.extras
andprivex.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.
- Added