CacheWrapper¶
-
class
privex.helpers.cache.CacheWrapper[source]¶ CacheWrapper is a small class designed to wrap an instance of
CacheAdapterand allow the adapter to be switched out at any time, using the static class attributecache_instance.This class is used for the singleton global variable
cachedFor convenience, if
cache_instanceisn’t set-up when something makes an adapter-dependant call, then the adapter class indefault_adapterwill be instantiated and stored incache_instance>>> # Using the ``: CacheAdapter`` type hinting will allow most IDEs to treat the wrapper as if it were >>> # a normal CacheAdapter child class, thus showing appropriate completion / usage warnings >>> c: CacheAdapter = CacheWrapper() >>> c.set('hello', 'world') >>> c['hello'] 'world'
You can replace the cache adapter singleton using the module function
adapter_set()(recommended)>>> from privex.helpers import cache, CacheWrapper >>> cache.adapter_set(cache.MemoryCache()) # Set the current adapter for both the cache module, and wrapper.
If you only plan to use this wrapper, then you can use
set_adapter()to update the current cache adapter instance.>>> CacheWrapper.set_adapter(cache.MemoryCache()) # Set the adapter only for the wrapper (aka ``cached``)
-
__init__() Initialize self. See help(type(self)) for accurate signature.
-
Methods¶
Methods
|
Attempt to get the singleton cache adapter from |
|