Repository navigation
Closed
Labels
priority: lowLow prioritytype: featureNew feature or requestworkload: daysLikely takes days to resolve
Milestone
Description
Part of #545.
Problem
Plugins have no storage beyond the current process (see #545), so caches aren't shared and counters (e.g. per-user API budgets) can't be enforced across workers or replicas.
Proposal
Add a small key-value store to the plugin context as ctx.store:
- API:
get(key),set(key, value, *, ttl=None),delete(key), and an atomicincrement(key, by=1, *, ttl=None, limit=None)that returns the new value, orNonewithout incrementing if it would exceedlimit. Onincrement, the TTL is set only when the counter is created (fixed window). - Keys: strings of 1 to 256 characters; values: I-JSON, size checked as compact JSON.
- Backend: one shared
plugin_storecollection in the app's MongoDB,_id= namespace + key, TTL index onexpires_at; reads also filter out expired entries. - Namespace: the normalized (PEP 503) distribution name of the plugin; built-in plugins use
foca. - In-memory fallback (per process) when no database is configured, and when the operator turns storage off for a plugin.
- Operator config in
plugins.defaults.storewith per-plugin overrides inplugins.available.<id>.store:enabled,max_entry_size,max_ttl(entries without a TTL get it). - Calls bounded by the hook deadline; failures raise a new
StoreError, which the engine treats like any other hook failure. - In-memory store for plugin tests in
foca.plugins.testing. - Docs: plugin guide (including hashing principals before using them as keys) and configuration.
No namespace size limit in this issue (see the follow-up child issue).
Done when
ctx.storeis available to plugins with both backends, configured and documented;- unit and integration tests (real MongoDB for TTL and atomic increments), 100% coverage.
Metadata
Metadata
Assignees
Labels
priority: lowLow prioritytype: featureNew feature or requestworkload: daysLikely takes days to resolve
Activity
fix(plugins): address Sourcery review of store