Skip to content

feat: implement cache backend with TTL support and integrate into con…#8

Merged
pikann merged 2 commits into
masterfrom
feature/plugin-cache
Jul 21, 2026
Merged

feat: implement cache backend with TTL support and integrate into con…#8
pikann merged 2 commits into
masterfrom
feature/plugin-cache

Conversation

@pikann

@pikann pikann commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

This pull request adds a Cache API for plugins — a TTL-based key-value store backed by the host's shared Valkey/Redis instance — alongside the existing DB/KV primitives, since neither of those can express "cache this for N minutes": DB is the shared Postgres, and KV is durable/non-expiring Postgres-backed storage.

New Cache API:

  • Added CacheBackend interface and Cache type to backends.go: Get(key) (string, bool), Set(key, value string, ttl time.Duration), Delete(key). A zero TTL stores the value without expiry.
  • Exposed via Context.Cache() (context.go), wired through newContext/NewContextForTest (context.go, testing.go) and the WASM dispatcher (dispatch.go).
  • Implemented wasmCacheBackend in wasm_backends.go, backed by three new host imports declared in wasm_imports.gopaca.cache_get, paca.cache_set (with a ttlSeconds argument), and paca.cache_delete — mirroring the existing storage_get/storage_set/storage_delete (KV) trio.
  • Added a stubCacheBackend in native_backends.go that always misses/no-ops, so non-WASM builds (go test, go vet) compile without a real host.
  • Added InMemoryCache to plugintest/backends.go — a map-backed test double with a fake clock (Advance) so tests can assert TTL expiry without a real sleep — and exposed it as Context.Cache in plugintest/plugintest.go.
  • Added plugintest/backends_test.go coverage: get-miss, set-then-get, zero-TTL-never-expires, expires-after-TTL, and delete.

Builds clean for both native (go build/go test) and GOOS=wasip1 GOARCH=wasm targets.

Follow-up (out of scope for this PR): the host-side implementation of paca.cache_get/set/delete — backed by Valkey/Redis and namespaced per plugin — is being wired up separately in the paca API service's plugin runtime. paca-plugin-dashboard is the first consumer, caching each panel's query result for 5 minutes (with immediate invalidation on panel edit/delete, and a bypass on manual reload) to avoid re-running potentially expensive aggregate queries on every dashboard render.

@pikann
pikann merged commit b832989 into master Jul 21, 2026
4 checks passed
@pikann
pikann deleted the feature/plugin-cache branch July 21, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant