feat: implement cache backend with TTL support and integrate into con…#8
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds a
CacheAPI for plugins — a TTL-based key-value store backed by the host's shared Valkey/Redis instance — alongside the existingDB/KVprimitives, since neither of those can express "cache this for N minutes":DBis the shared Postgres, andKVis durable/non-expiring Postgres-backed storage.New Cache API:
CacheBackendinterface andCachetype tobackends.go:Get(key) (string, bool),Set(key, value string, ttl time.Duration),Delete(key). A zero TTL stores the value without expiry.Context.Cache()(context.go), wired throughnewContext/NewContextForTest(context.go,testing.go) and the WASM dispatcher (dispatch.go).wasmCacheBackendinwasm_backends.go, backed by three new host imports declared inwasm_imports.go—paca.cache_get,paca.cache_set(with attlSecondsargument), andpaca.cache_delete— mirroring the existingstorage_get/storage_set/storage_delete(KV) trio.stubCacheBackendinnative_backends.gothat always misses/no-ops, so non-WASM builds (go test,go vet) compile without a real host.InMemoryCachetoplugintest/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 asContext.Cacheinplugintest/plugintest.go.plugintest/backends_test.gocoverage: get-miss, set-then-get, zero-TTL-never-expires, expires-after-TTL, and delete.Builds clean for both native (
go build/go test) andGOOS=wasip1 GOARCH=wasmtargets.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 thepacaAPI service's plugin runtime.paca-plugin-dashboardis 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.