collective.redismemoize.config#
Settings, read from the environment once per process.
Settings, read from the environment once per process.
The environment rather than the Plone registry: the cache chooser runs outside any site, the first time a cached function is called, and its answer has to be the same for every site the process serves. It is also how Docker and Swarm deployments configure everything else.
This module is pure Python and never imports Zope.
- collective.redismemoize.config.SCHEMES = ('redis', 'rediss', 'unix')#
Schemes redis-py accepts in
Redis.from_url.
- collective.redismemoize.config.DEFAULTS: dict[str, str | None] = {'REDIS_MEMOIZE_EXCLUDE': '', 'REDIS_MEMOIZE_INCLUDE': '', 'REDIS_MEMOIZE_MAX_SIZE': '1048576', 'REDIS_MEMOIZE_PREFIX': 'plone.memoize', 'REDIS_MEMOIZE_RETRY_AFTER': '30', 'REDIS_MEMOIZE_TIMEOUT': '0.25', 'REDIS_MEMOIZE_TTL': '86400', 'REDIS_MEMOIZE_URL': None}#
Every variable this package reads, with its default.
Nonemeans unset.
- class collective.redismemoize.config.Settings[source]#
Bases:
objectThe package configuration, validated.
- Parameters:
url -- Redis URL, or
Nonewhen the package is inert.prefix -- Namespace every key starts with.
ttl -- Lifetime of a stored value, in seconds.
timeout -- Socket connect and read timeout, in seconds.
retry_after -- Seconds to leave Redis alone after a failure.
max_size -- Largest serialized value sent to Redis, in bytes.
include --
fnmatchpatterns of function names allowed into Redis; empty allows every function.exclude -- Patterns always kept in RAM; they win over
include.
- property active: bool#
Report whether a Redis URL is configured.
- Returns:
Falsemeans the package behaves exactly like stockplone.memoize.
- property redacted_url: str | None#
Return the URL with any password replaced by
***.- Returns:
The URL safe to log or show, or
Nonewhen unset.
- __init__(url=None, prefix='plone.memoize', ttl=86400, timeout=0.25, retry_after=30.0, max_size=1048576, include=(), exclude=())#
- collective.redismemoize.config.from_environ(environ=None)[source]#
Build and validate settings from an environment.
- Parameters:
environ (dict[str, str] | None) -- Mapping to read;
os.environby default.- Returns:
The settings.
- Raises:
ValueError -- Naming the variable, when a value is invalid.
- Return type:
- collective.redismemoize.config.get_settings()[source]#
Return the process settings, reading the environment the first time.
- Returns:
The settings.
- Raises:
ValueError -- When a variable is invalid.
- Return type:
- collective.redismemoize.config.reload()[source]#
Read the environment again, replacing the process settings.
Tests use it after changing a variable; a running site never needs it.
- Returns:
The new settings.
- Raises:
ValueError -- When a variable is invalid.
- Return type: