Skip to content

cachestore

The cache-port contract domain.

Modules:

  • port – The CacheStore port — ephemeral key/value storage behind a narrow interface.

Classes:

  • CacheStore – Ephemeral key/value cache port. Implementations back it in-process or with Redis.

Bases: Protocol

Ephemeral key/value cache port. Implementations back it in-process or with Redis.

Values are strings — callers serialize richer types themselves, keeping the port trivially implementable everywhere. TTLs are seconds; a key with no TTL persists until deleted.

Functions:

  • delete – Remove key. A no-op when the key is absent.
  • exists – Return whether key is present and unexpired.
  • expire – Set key to expire after ttl seconds. A no-op when the key is absent.
  • get – Return the value for key, or None if absent or expired.
  • incr – Atomically add amount to the integer at key (0 if absent); return the result.
  • set – Store value under key. With ttl (seconds), the key expires after it.

moderatorim.sdk.cachestore.CacheStore.delete

Section titled “moderatorim.sdk.cachestore.CacheStore.delete”
delete(key)

Remove key. A no-op when the key is absent.

moderatorim.sdk.cachestore.CacheStore.exists

Section titled “moderatorim.sdk.cachestore.CacheStore.exists”
exists(key)

Return whether key is present and unexpired.

moderatorim.sdk.cachestore.CacheStore.expire

Section titled “moderatorim.sdk.cachestore.CacheStore.expire”
expire(key, ttl)

Set key to expire after ttl seconds. A no-op when the key is absent.

get(key)

Return the value for key, or None if absent or expired.

moderatorim.sdk.cachestore.CacheStore.incr

Section titled “moderatorim.sdk.cachestore.CacheStore.incr”
incr(key, *, amount=1)

Atomically add amount to the integer at key (0 if absent); return the result.

set(key, value, *, ttl=None)

Store value under key. With ttl (seconds), the key expires after it.

The CacheStore port — ephemeral key/value storage behind a narrow interface.

The core caches its own data (sessions, rate-limit counters, short-lived values) against this port. It is deliberately narrow — string values, TTL, and an atomic counter — so every implementation is trivial and no caller can smuggle backend-specific semantics through it.

Unlike :class:~moderatorim.sdk.datastore.DataStore, a CacheStore is NOT a discovered “backend” unit selected in the setup wizard: it is caching INFRASTRUCTURE the core instantiates from configuration (an in-memory default, or Redis when a URL is configured). The port lives in the SDK so it is a frozen public contract a third party could also implement.

Classes:

  • CacheStore – Ephemeral key/value cache port. Implementations back it in-process or with Redis.

moderatorim.sdk.cachestore.port.CacheStore

Section titled “moderatorim.sdk.cachestore.port.CacheStore”

Bases: Protocol

Ephemeral key/value cache port. Implementations back it in-process or with Redis.

Values are strings — callers serialize richer types themselves, keeping the port trivially implementable everywhere. TTLs are seconds; a key with no TTL persists until deleted.

Functions:

  • delete – Remove key. A no-op when the key is absent.
  • exists – Return whether key is present and unexpired.
  • expire – Set key to expire after ttl seconds. A no-op when the key is absent.
  • get – Return the value for key, or None if absent or expired.
  • incr – Atomically add amount to the integer at key (0 if absent); return the result.
  • set – Store value under key. With ttl (seconds), the key expires after it.
moderatorim.sdk.cachestore.port.CacheStore.delete
Section titled “moderatorim.sdk.cachestore.port.CacheStore.delete”
delete(key)

Remove key. A no-op when the key is absent.

moderatorim.sdk.cachestore.port.CacheStore.exists
Section titled “moderatorim.sdk.cachestore.port.CacheStore.exists”
exists(key)

Return whether key is present and unexpired.

moderatorim.sdk.cachestore.port.CacheStore.expire
Section titled “moderatorim.sdk.cachestore.port.CacheStore.expire”
expire(key, ttl)

Set key to expire after ttl seconds. A no-op when the key is absent.

moderatorim.sdk.cachestore.port.CacheStore.get
Section titled “moderatorim.sdk.cachestore.port.CacheStore.get”
get(key)

Return the value for key, or None if absent or expired.

moderatorim.sdk.cachestore.port.CacheStore.incr
Section titled “moderatorim.sdk.cachestore.port.CacheStore.incr”
incr(key, *, amount=1)

Atomically add amount to the integer at key (0 if absent); return the result.

moderatorim.sdk.cachestore.port.CacheStore.set
Section titled “moderatorim.sdk.cachestore.port.CacheStore.set”
set(key, value, *, ttl=None)

Store value under key. With ttl (seconds), the key expires after it.