SessionStore#

class scikitplot.cleanprompt.SessionStore(ttl_seconds=3600, max_sessions=256)[source]#

Bounded, expiring, server-side store of vaults.

Parameters:
ttl_secondsint, default=3600

How long a vault is retained after its last use.

max_sessionsint, default=256

Most sessions retained. When full, the least recently used session is evicted and its vault cleared.

Raises:
PolicyError

If a bound is not a positive integer.

Parameters:
  • ttl_seconds (int)

  • max_sessions (int)

Notes

Developer notes. Both bounds exist because this store holds personal data indefinitely otherwise: a long-running local app would accumulate every vault every visitor ever created. Eviction calls clear, so an evicted vault stops referencing its secrets rather than merely becoming unreachable.

A threading.Lock guards the mapping because a Flask development server is threaded by default. The lock is held only for dictionary operations, never across a redaction.

Tokens come from secrets.token_urlsafe, so they are unguessable; a session identifier is the only thing standing between one browser tab and another’s vault.

Examples

>>> store = SessionStore(ttl_seconds=60, max_sessions=4)
>>> token = store.put(Vault({"[EMAIL-1]": "a@b.co"}))
>>> store.get(token)["[EMAIL-1]"]
'a@b.co'
drop(token)[source]#

Remove and clear the vault for token, if present.

Parameters:

token (str | None)

Return type:

None

get(token)[source]#

Return the vault for token, refreshing its expiry.

Parameters:
tokenstr or None

The token from the session cookie.

Returns:
Vault or None

The vault, or None when the token is unknown or expired.

Parameters:

token (str | None)

Return type:

Vault | None

put(vault, token=None)[source]#

Store vault and return its token.

Parameters:
vaultVault

The vault to retain.

tokenstr, optional

Reuse an existing token, replacing its vault. A replaced vault is cleared.

Returns:
str

The token identifying this vault.

Parameters:
Return type:

str