Documentation
¶
Overview ¶
Package swr caches typed, revisioned observations in a local Otter cache and a shared Clicky store. Callers authorize reads and supply authoritative loaders.
Index ¶
Examples ¶
Constants ¶
View Source
const BatchSize = 100
Variables ¶
View Source
var ErrSuperseded = errors.New("cache publication superseded")
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[T any] struct { // contains filtered or unexported fields }
Example ¶
package main
import (
"context"
"fmt"
"time"
"github.com/flanksource/clicky/cache"
"github.com/flanksource/clicky/cache/swr"
)
func main() {
ctx := context.Background()
store := cache.NewMemory().(cache.ConditionalStore)
snapshots, err := swr.New[string](swr.Config{Shared: store, Policy: swr.Policy{
FreshFor: time.Minute, MaxFreshFor: time.Hour, StaleFor: 72 * time.Hour,
MaxLocalAge: 2 * time.Hour, MaxSharedAge: 7 * 24 * time.Hour,
}})
if err != nil {
panic(err)
}
scope := swr.Scope{Prefix: "example:state:v1:tenant-a:issue", Group: "connection-a"}
ids := []string{"TASK-21"}
err = snapshots.Revalidate(ctx, scope, swr.Refresh[string]{IDs: ids,
Load: func(context.Context, map[string]string) (map[string]swr.Loaded[string], error) {
return map[string]swr.Loaded[string]{"TASK-21": {Data: "Review roadmap", Revision: "3"}}, nil
}})
if err != nil {
panic(err)
}
rows, err := snapshots.Lookup(ctx, scope, ids)
if err != nil {
panic(err)
}
fmt.Println(rows["TASK-21"].Data)
}
Output: Review roadmap
func (*Cache[T]) Invalidate ¶
type CodecConfig ¶
type Invalidation ¶
type Refresh ¶
type Refresh[T any] struct { IDs []string Guards []cache.Guard // Load returns observations for the requested IDs. An omitted ID is unchanged // in the cache. An unchanged source revision still needs a successful observation. Load func(context.Context, map[string]string) (map[string]Loaded[T], error) }
type Scope ¶
func (Scope) ControlKey ¶
Click to show internal directories.
Click to hide internal directories.