Cache
Cache providers are plugin-bound utilities for short-lived key/value state.
They are configured under providers.cache and attached to apps with
apps.<name>.cache.
Cache providers use the same provider-entry plus app SDK binding pattern as IndexedDB.
Configuring providers.cache
providers:
cache:
session:
source:
package: github.com/your-org/gestalt-cache-provider
version: 0.0.1
config:
namespace: session
rate_limit:
source:
package: github.com/your-org/gestalt-cache-provider
version: 0.0.1
config:
namespace: rate_limit
apps:
search:
source: ./providers/search/manifest.yaml
cache:
- session
- rate_limitThis example binds two caches into the search app. Both bindings use the
same provider package, but they receive different provider-specific config.
That is a common pattern for keeping session and rate-limit state separate
without introducing a second cache technology.
Using Cache from a plugin
Go
import (
"context"
"log"
"time"
gestalt "github.com/valon-technologies/gestalt/sdk/go"
)
ctx := context.Background()
cache, err := gestalt.Cache("session")
if err != nil {
log.Fatal(err)
}
defer cache.Close()
if err := cache.Set(ctx, "user:1", []byte("alpha"), gestalt.CacheSetOptions{
TTL: 5 * time.Minute,
}); err != nil {
log.Fatal(err)
}
value, found, err := cache.Get(ctx, "user:1")
if err != nil {
log.Fatal(err)
}
_ = value
_ = foundThe host resolves the configured cache bindings and exposes them to the plugin through the language SDK. App code does not choose backend endpoints directly at runtime. It just opens the bound cache by name.
Building your own cache provider
Manifest
A cache provider manifest declares kind: cache:
kind: cache
source: github.com/your-org/gestalt-cache-provider
version: 0.0.1
displayName: Example Cache
description: Cache provider backed by your cache service.
spec:
configSchemaPath: ./cache_config.jsonGo
package examplecache
import (
"context"
"time"
gestalt "github.com/valon-technologies/gestalt/sdk/go"
)
type ExampleCache struct{}
func New() *ExampleCache { return &ExampleCache{} }
func (p *ExampleCache) Get(ctx context.Context, key string) ([]byte, bool, error) {
panic("implement cache get")
}
func (p *ExampleCache) GetMany(ctx context.Context, keys []string) (map[string][]byte, error) {
panic("implement cache get many")
}
func (p *ExampleCache) Set(ctx context.Context, key string, value []byte, opts gestalt.CacheSetOptions) error {
panic("implement cache set")
}
func (p *ExampleCache) SetMany(ctx context.Context, entries []gestalt.CacheEntry, opts gestalt.CacheSetOptions) error {
panic("implement cache set many")
}
func (p *ExampleCache) Delete(ctx context.Context, key string) (bool, error) {
panic("implement cache delete")
}
func (p *ExampleCache) DeleteMany(ctx context.Context, keys []string) (int64, error) {
panic("implement cache delete many")
}
func (p *ExampleCache) Touch(ctx context.Context, key string, ttl time.Duration) (bool, error) {
panic("implement cache touch")
}Release flow
For packaging, lock/sync, and release behavior, see Releasing provider packages.
What to read next
If you want the full config reference, read Config File. For plugin-side binding behavior in the broader config model, see Configuration.