3.2.0 - Added MemcachedCache + privex.helpers.cache.extra, plus various other additions
Latest-
privex.helpers.settings
-
Added
DEFAULT_CACHE_ADAPTERwhich 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_ADAPTERwhich 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_adapterfunction andADAPTER_MAPdictionary inprivex.helpers.cache, it's now possible to reference cache adapters by simple names such asmemcached,redis,sqlite3,memoryetc. - 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
MemcachedCachemodule, which contains the synchronous cache adapterMemcachedCache. This is simply a synchronous version ofAsyncMemcachedCachethat usespylibmcinstead ofaiomcache. -
Added
ADAPTER_MAPdictionary, which maps aliases such asmemcached,redis,sqlite3,memoryetc. to their respective synchronous and asyncio adapter module paths, which can be loaded using the newly addedimport_adapterfunction, or simply usingadapter_set/async_adapter_set. -
Added
import_adapterfunction, 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+AsyncCacheWrapperso 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
extrasmodule-
CacheManagerMixinis 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_cacheby intercepting the first argument of a method call. -
z_cache- A special method caching decorator which is designed to integrate with classes that extend.CacheManagerMixinThis 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 wrappingorlist iteration
- Added new small helper function
-
privex.helpers.plugin
- Added various functions for managing memcached instances via the
pylibmclibraryconnect_memcached- create a new memcachedClientobjectget_memcached- get or create a MemcachedClientobject shared by your threadclose_memcached- close the MemcachedClientconnection and delete it from the threadstorereset_memcached- close the sharedClientthen re-create it again.configure_memcached- configure Memcached settings then automatically reset the sharedClientinstance.
- Added new
HAS_MEMCACHEDboolean value, to track whether synchronous memcached viapylibmcis available
- Added various functions for managing memcached instances via the
-
General stuff
- Added
pylibmcto extras/cache.txt - Added some missing packages to the
Pipfile- and synchronisedPipfile.lock - Added
.envto.gitignore - Created unit tests for the new
CacheManagerMixinclass andz_cachedecorator - Created unit tests for the new
MemcachedCachecache adapter - Fixed the
livecommand indocs/Makefilefor newersphinx-autobuild - Added
SqliteCacheandMemcachedCacheto the docs - Added
privex.helpers.cache.extrasandprivex.helpers.cache.post_depto 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