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. None means unset.

class collective.redismemoize.config.Settings[source]#

Bases: object

The package configuration, validated.

Parameters:
  • url -- Redis URL, or None when 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 -- fnmatch patterns of function names allowed into Redis; empty allows every function.

  • exclude -- Patterns always kept in RAM; they win over include.

url: str | None = None#
prefix: str = 'plone.memoize'#
ttl: int = 86400#
timeout: float = 0.25#
retry_after: float = 30.0#
max_size: int = 1048576#
include: tuple[str, ...] = ()#
exclude: tuple[str, ...] = ()#
property active: bool#

Report whether a Redis URL is configured.

Returns:

False means the package behaves exactly like stock plone.memoize.

exclusion_reason(fun_name)[source]#

Explain why a function is kept out of Redis by configuration.

Parameters:

fun_name (str) -- Dotted name of the cached function.

Returns:

The reason, or None when the function may use Redis.

Return type:

str | None

property redacted_url: str | None#

Return the URL with any password replaced by ***.

Returns:

The URL safe to log or show, or None when unset.

__init__(url=None, prefix='plone.memoize', ttl=86400, timeout=0.25, retry_after=30.0, max_size=1048576, include=(), exclude=())#
Parameters:
Return type:

None

collective.redismemoize.config.redact_url(url)[source]#

Hide the password of a URL.

Parameters:

url (str | None) -- A Redis URL, or None.

Returns:

The URL with its password replaced by ***.

Return type:

str | None

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.environ by default.

Returns:

The settings.

Raises:

ValueError -- Naming the variable, when a value is invalid.

Return type:

Settings

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:

Settings

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:

Settings