Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def doublecache(
client, key_prefix, expire=0, coder=None,
user_interface=DoubleCacheUserInterface):
from ring.func.sync import ExpirableDictStorage
from ring.func.asyncio import convert_storage
return factory(
client, key_prefix=key_prefix, on_manufactured=None,
user_interface=user_interface,
storage_class=convert_storage(ExpirableDictStorage),
miss_value=None, expire_default=expire, coder=coder)
>>> @ring.aioredis_hash(redis_coroutine, ...)
>>> async def by_coroutine(...):
>>> ...
:see: :func:`ring.func.asyncio.CacheUserInterface` for single access
sub-functions.
:see: :func:`ring.func.asyncio.BulkInterfaceMixin` for bulk access
sub-functions.
:see: :func:`ring.redis` for non-asyncio version.
"""
expire = None
if asyncio.iscoroutine(redis):
redis = SingletonCoroutineProxy(redis)
return fbase.factory(
(redis, hash_key), key_prefix=key_prefix, on_manufactured=factory_doctor,
user_interface=user_interface, storage_class=storage_class,
miss_value=None, expire_default=expire, coder=coder,
**kwargs)
... ...
:param object key_refactor: The default key refactor may hash the cache
key when it doesn't meet Memcached key restriction.
:see: :func:`ring.func.sync.CacheUserInterface` for single access
sub-functions.
:see: :func:`ring.func.sync.BulkInterfaceMixin` for bulk access
sub-functions.
:see: :func:`ring.aiomcache` for :mod:`asyncio` version.
"""
from ring._memcache import key_refactor
miss_value = None
return fbase.factory(
client, key_prefix=key_prefix, on_manufactured=None,
user_interface=user_interface, storage_class=storage_class,
miss_value=miss_value, expire_default=expire, coder=coder,
key_refactor=key_refactor,
**kwargs)
backend=django_cache.cache, key_prefix=None, expire=None, coder=None,
user_interface=CacheUserInterface, storage_class=LowLevelCacheStorage):
"""A typical ring-style cache based on Django's low-level cache API.
:param Union[str,object] backend: Django's cache config key for
:data:`django.core.cache.caches` or Django cache object.
:see: `Django's cache framework: Setting up the cache`_ to configure django
cache.
:see: `Django's cache framework: The low-level cache API`_ for the backend.
.. _`Django's cache framework: Setting up the cache`: https://docs.djangoproject.com/en/2.0/topics/cache/#setting-up-the-cache
.. _`Django's cache framework: The low-level cache API`: https://docs.djangoproject.com/en/2.0/topics/cache/#the-low-level-cache-api
""" # noqa
backend = promote_backend(backend)
return fbase.factory(
backend, key_prefix=key_prefix, on_manufactured=None,
user_interface=user_interface, storage_class=storage_class,
miss_value=None, expire_default=expire, coder=coder)
:param object key_refactor: The default key refactor may hash the cache
key when it doesn't meet Memcached key restriction.
:see: :func:`ring.func.asyncio.CacheUserInterface` for single access
sub-functions.
:see: :func:`ring.func.asyncio.BulkInterfaceMixin` for bulk access
sub-functions.
:see: :func:`ring.func.sync.memcache` for non-asyncio version.
.. _Memcached: http://memcached.org/
.. _aiomcache: https://pypi.org/project/aiomcache/
"""
from ring._memcache import key_refactor
return fbase.factory(
client, key_prefix=key_prefix, on_manufactured=factory_doctor,
user_interface=user_interface, storage_class=storage_class,
miss_value=None, expire_default=expire, coder=coder,
key_encoding=key_encoding, key_refactor=key_refactor,
**kwargs)
Note that the first parameter of every sub-function originally is a
:class:`django.request.HttpRequest` object but a tuple here.
The second item of the tuple provides a hint for the request path of
`article_list`. Because Django expects the cache key varies by request
path, it is required to find the corresponding cache key.
:see: `Django's cache framework: The per-view cache `_
:see: :func:`django.views.decorators.cache.cache_page`.
""" # noqa
middleware_class = CacheMiddleware
middleware = middleware_class(
cache_timeout=timeout, cache_alias=cache, key_prefix=key_prefix)
return fbase.factory(
middleware, key_prefix='', on_manufactured=None,
user_interface=user_interface, storage_class=storage_class,
# meaningless parameters below
miss_value=None, expire_default=None, coder=None)
operation features, unlike :func:`functools.lru_cache`.
:param ring.func.lru_cache.LruCache lru: Cache storage. If the default
value :data:`None` is given, a new `LruCache`
object will be created. (Recommended)
:param int maxsize: The maximum size of the cache storage.
:see: :func:`functools.lru_cache` for LRU cache basics.
:see: :func:`ring.func.sync.CacheUserInterface` for sub-functions.
"""
if lru is None:
lru = lru_mod.LruCache(maxsize)
if key_prefix is None:
key_prefix = ''
return fbase.factory(
lru, key_prefix=key_prefix, on_manufactured=None,
user_interface=user_interface, storage_class=storage_class,
miss_value=None, expire_default=expire, coder=coder,
**kwargs)
>>> @ring.redis_hash(client, ...)
... ...
:see: :func:`ring.func.sync.CacheUserInterface` for single access
sub-functions.
:see: :func:`ring.func.sync.BulkInterfaceMixin` for bulk access
sub-functions.
:see: Redis_ for Redis documentation.
.. _Redis: http://redis.io/
.. _Redis HASH commands: https://redis.io/commands#hash
.. _redis-py: https://pypi.org/project/redis/
"""
expire = None
return fbase.factory(
(client, hash_key), key_prefix=key_prefix, on_manufactured=None,
user_interface=user_interface, storage_class=storage_class,
miss_value=None, expire_default=expire, coder=coder,
**kwargs)
def dict(
obj, key_prefix=None, expire=None, coder=None,
user_interface=CacheUserInterface, storage_class=None,
**kwargs):
""":class:`dict` interface for :mod:`asyncio`.
:see: :func:`ring.func.sync.dict` for common description.
"""
if storage_class is None:
if expire is None:
storage_class = fsync.PersistentDictStorage
else:
storage_class = fsync.ExpirableDictStorage
return fbase.factory(
obj, key_prefix=key_prefix, on_manufactured=None,
user_interface=user_interface,
storage_class=convert_storage(storage_class),
miss_value=None, expire_default=expire, coder=coder,
**kwargs)