def __init__(self, host: _t.Any = "localhost", port: int = 6379, password: _t.Optional[str] = None, db: int = 0, default_timeout: int = 300, key_prefix: _t.Optional[str] = None, **kwargs: _t.Any): BaseCache.__init__(self, default_timeout) if host is None: raise ValueError("RedisCache host parameter may not be None") if isinstance(host, str): try: import redis except ImportError as err: raise RuntimeError("no redis module found") from err if kwargs.get("decode_responses", None): raise ValueError( "decode_responses is not supported by RedisCache.") self._client = redis.Redis(host=host, port=port, password=password, db=db, **kwargs) else: self._client = host self.key_prefix = key_prefix or ""
def __init__(self, host='localhost', port=6379, password=None, db=0, default_timeout=300, key_prefix=None, **kwargs): BaseCache.__init__(self, default_timeout) if host is None: raise ValueError('RedisCache host parameter may not be None') if isinstance(host, string_types): try: import redis except ImportError: raise RuntimeError('no redis module found') if kwargs.get('decode_responses', None): raise ValueError('decode_responses is not supported by ' 'RedisCache.') self._client = redis.Redis(host=host, port=port, password=password, db=db, **kwargs) else: self._client = host self.key_prefix = key_prefix or ''
def __init__( self, threshold: int = 500, default_timeout: int = 300, ): BaseCache.__init__(self, default_timeout) self._cache: _t.Dict[str, _t.Any] = {} self._threshold = threshold or 500 # threshold = 0
def __init__(self, servers=None, default_timeout=300, key_prefix=None): BaseCache.__init__(self, default_timeout) if servers is None or isinstance(servers, (list, tuple)): if servers is None: servers = ['10.28.141.171:11211'] self._client = self.import_preferred_memcache_lib(servers) if self._client is None: raise RuntimeError('no memcache module found') else: # NOTE: servers is actually an already initialized memcache # client. self._client = servers self.key_prefix = to_native(key_prefix)
def __init__(self, default_timeout=300, cache=''): BaseCache.__init__(self, default_timeout) if platform.python_implementation() == 'PyPy': raise RuntimeError("uWSGI caching does not work under PyPy, see " "the docs for more details.") try: import uwsgi self._uwsgi = uwsgi except ImportError: raise RuntimeError("uWSGI could not be imported, are you " "running under uWSGI?") self.cache = cache
def _normalize_timeout(self, timeout): timeout = BaseCache._normalize_timeout(self, timeout) if timeout != 0: timeout = time() + timeout return int(timeout)
def __init__(self, cache_dir, threshold=500, default_timeout=300, mode=0o600): BaseCache.__init__(self, default_timeout) self._path = cache_dir self._threshold = threshold self._mode = mode try: os.makedirs(self._path) except OSError as ex: if ex.errno != errno.EEXIST: raise self._update_count(value=len(self._list_dir()))
def __init__(self, cache_dir, threshold=500, default_timeout=300, mode=0o600): BaseCache.__init__(self, default_timeout) self._path = cache_dir self._threshold = threshold self._mode = mode try: os.makedirs(self._path) except OSError as ex: if ex.errno != errno.EEXIST: raise # If there are many files and a zero threshold, # the list_dir can slow initialisation massively if self._threshold != 0: self._update_count(value=len(self._list_dir()))
def __init__( self, servers: _t.Any = None, default_timeout: int = 300, key_prefix: _t.Optional[str] = None, ): BaseCache.__init__(self, default_timeout) if servers is None or isinstance(servers, (list, tuple)): if servers is None: servers = ["127.0.0.1:11211"] self._client = self.import_preferred_memcache_lib(servers) if self._client is None: raise RuntimeError("no memcache module found") else: # NOTE: servers is actually an already initialized memcache # client. self._client = servers self.key_prefix = key_prefix
def __init__( self, default_timeout: int = 300, cache: str = "", ): BaseCache.__init__(self, default_timeout) if platform.python_implementation() == "PyPy": raise RuntimeError("uWSGI caching does not work under PyPy, see " "the docs for more details.") try: import uwsgi # type: ignore self._uwsgi = uwsgi except ImportError as err: raise RuntimeError( "uWSGI could not be imported, are you running under uWSGI?" ) from err self.cache = cache
def _normalize_timeout(self, timeout): timeout = BaseCache._normalize_timeout(self, timeout) if timeout > 0: timeout = int(time()) + timeout return timeout
def _normalize_timeout(self, timeout): timeout = BaseCache._normalize_timeout(self, timeout) if timeout == 0: timeout = -1 return timeout
def _normalize_timeout(self, timeout: _t.Optional[int]) -> int: timeout = BaseCache._normalize_timeout(self, timeout) if timeout != 0: timeout = int(time()) + timeout return int(timeout)
def _normalize_timeout(self, timeout: _t.Optional[int]) -> int: timeout = BaseCache._normalize_timeout(self, timeout) if timeout == 0: timeout = -1 return timeout
def __init__(self, threshold=500, default_timeout=300): BaseCache.__init__(self, default_timeout) self._cache = {} self.clear = self._cache.clear self._threshold = threshold