session

package
v0.6.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 26 Imported by: 0

README

Session Cache Implementation

This package provides session cache implementations for the Baton SDK. It includes both in-memory and gRPC-based implementations.

Overview

The session cache is used to store temporary data during sync operations. It provides a key-value store interface with support for:

  • Basic CRUD operations (Get, Set, Delete, Clear)
  • Batch operations (GetMany, SetMany)
  • Namespace isolation using sync IDs
  • Prefix support for key organization
  • Context-based configuration
  • An implemention will be chosen at runtime (the grpc interface will be used if the build tag is specified).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSessionStoreDisabled = fmt.Errorf("session store is disabled by connector author. It must be explicitly enabled via RunConnector WithSessionStoreEnabled()")

Functions

func Chunk added in v0.5.0

func Chunk[T any](items []T, chunkSize int) iter.Seq[[]T]

func GetAllJSON

func GetAllJSON[T any](ctx context.Context, ss sessions.SessionStore, opt ...sessions.SessionStoreOption) (map[string]T, error)

func GetJSON

func GetJSON[T any](ctx context.Context, ss sessions.SessionStore, key string, opt ...sessions.SessionStoreOption) (T, bool, error)

func GetManyJSON

func GetManyJSON[T any](ctx context.Context, ss sessions.SessionStore, keys []string, opt ...sessions.SessionStoreOption) (map[string]T, error)

func NewGRPCSessionClient added in v0.5.0

func NewGRPCSessionClient(ctx context.Context, accessToken string, dpopKey *jose.JSONWebKey, opt ...sessions.SessionStoreConstructorOption) (v1.BatonSessionServiceClient, error)

NewGRPCSessionClient creates a new gRPC session service client using existing DPoP credentials. It reuses an existing access token and DPoP key instead of performing a new authentication round. It reads the session service address from the BATON_SESSION_SERVICE_ADDR environment variable, defaulting to "localhost:50051" if not set.

func NewGRPCSessionStore added in v0.5.3

NewGRPCSessionStore creates a new gRPC session cache instance.

func SetJSON

func SetJSON[T any](ctx context.Context, ss sessions.SessionStore, key string, item T, opt ...sessions.SessionStoreOption) error

func SetManyJSON

func SetManyJSON[T any](ctx context.Context, ss sessions.SessionStore, items map[string]T, opt ...sessions.SessionStoreOption) error

func StartGRPCSessionServerWithOptions added in v0.5.0

func StartGRPCSessionServerWithOptions(ctx context.Context, listener net.Listener, sessionServer v1.BatonSessionServiceServer, opts ...grpc.ServerOption) error

func UnrollGetAll added in v0.5.3

func UnrollGetAll[T any](ctx context.Context, ss GetAllable[T], opt ...sessions.SessionStoreOption) (map[string]T, error)

func UnrollGetMany added in v0.5.3

func UnrollGetMany[T any](ctx context.Context, ss GetManyable[T], keys []string, opt ...sessions.SessionStoreOption) (map[string]T, error)

func UnrollSetMany added in v0.5.3

func UnrollSetMany[T any](ctx context.Context, ss SetManyable[T], items iter.Seq2[SizedItem[T], error], opt ...sessions.SessionStoreOption) error

UnrollSetMany takes an iterator of sized items and batches them into SetMany calls, respecting both MaxKeysPerRequest and MaxSessionStoreSizeLimit. The iterator yields (item, error) pairs; iteration stops on the first error.

Types

type CacheItem added in v0.5.7

type CacheItem struct {
	Value []byte
}

type Codec added in v0.5.0

type Codec[T any] interface {
	Encode(value T) ([]byte, error)
	Decode(data []byte) (T, error)
}

type GRPCSessionServer added in v0.5.0

type GRPCSessionServer struct {
	// contains filtered or unexported fields
}

func NewGRPCSessionServer added in v0.5.0

func NewGRPCSessionServer() *GRPCSessionServer

func (*GRPCSessionServer) Clear added in v0.5.0

func (*GRPCSessionServer) Delete added in v0.5.0

func (*GRPCSessionServer) DeleteMany added in v0.5.0

func (*GRPCSessionServer) Get added in v0.5.0

func (*GRPCSessionServer) GetAll added in v0.5.0

func (*GRPCSessionServer) GetMany added in v0.5.0

func (*GRPCSessionServer) Set added in v0.5.0

func (*GRPCSessionServer) SetMany added in v0.5.0

func (*GRPCSessionServer) SetSessionStore added in v0.5.0

func (s *GRPCSessionServer) SetSessionStore(ctx context.Context, store sessions.SessionStore)

func (*GRPCSessionServer) Validate added in v0.5.0

func (s *GRPCSessionServer) Validate() error

type GRPCSessionStoreClient added in v0.5.3

type GRPCSessionStoreClient struct {
	// contains filtered or unexported fields
}

func (*GRPCSessionStoreClient) Clear added in v0.5.3

Clear removes all values from the cache.

func (*GRPCSessionStoreClient) Delete added in v0.5.3

Delete removes a value from the cache by key.

func (*GRPCSessionStoreClient) Get added in v0.5.3

Get retrieves a value from the cache by key.

func (*GRPCSessionStoreClient) GetAll added in v0.5.3

func (g *GRPCSessionStoreClient) GetAll(ctx context.Context, pageToken string, opt ...sessions.SessionStoreOption) (map[string][]byte, string, error)

func (*GRPCSessionStoreClient) GetMany added in v0.5.3

func (g *GRPCSessionStoreClient) GetMany(ctx context.Context, keys []string, opt ...sessions.SessionStoreOption) (map[string][]byte, []string, error)

GetMany retrieves multiple values from the cache by keys.

func (*GRPCSessionStoreClient) Set added in v0.5.3

Set stores a value in the cache with the given key.

func (*GRPCSessionStoreClient) SetMany added in v0.5.3

func (g *GRPCSessionStoreClient) SetMany(ctx context.Context, values map[string][]byte, opt ...sessions.SessionStoreOption) error

SetMany stores multiple values in the cache.

type GetAllable added in v0.5.3

type GetAllable[T any] interface {
	GetAll(ctx context.Context, pageToken string, opt ...sessions.SessionStoreOption) (map[string]T, string, error)
}

type GetManyable added in v0.5.3

type GetManyable[T any] interface {
	GetMany(ctx context.Context, keys []string, opt ...sessions.SessionStoreOption) (map[string]T, []string, error)
}

type IntCodec added in v0.5.0

type IntCodec struct{}

func (*IntCodec) Decode added in v0.5.0

func (i *IntCodec) Decode(data []byte) (int, error)

func (*IntCodec) Encode added in v0.5.0

func (i *IntCodec) Encode(value int) ([]byte, error)

type JSONCodec added in v0.5.0

type JSONCodec[T any] struct{}

func (*JSONCodec[T]) Decode added in v0.5.0

func (j *JSONCodec[T]) Decode(data []byte) (T, error)

func (*JSONCodec[T]) Encode added in v0.5.0

func (j *JSONCodec[T]) Encode(value T) ([]byte, error)

type MemorySessionCache

type MemorySessionCache struct {
	// contains filtered or unexported fields
}

func NewMemorySessionCache

func NewMemorySessionCache(otterOptions *otter.Options[string, []byte], ss sessions.SessionStore) (*MemorySessionCache, error)

func (*MemorySessionCache) Clear

func (*MemorySessionCache) Delete

func (*MemorySessionCache) Get

func (*MemorySessionCache) GetAll

func (m *MemorySessionCache) GetAll(ctx context.Context, pageToken string, opt ...sessions.SessionStoreOption) (map[string][]byte, string, error)

GetAll always calls the backing store and caches the results.

func (*MemorySessionCache) GetMany

func (m *MemorySessionCache) GetMany(ctx context.Context, keys []string, opt ...sessions.SessionStoreOption) (map[string][]byte, []string, error)

func (*MemorySessionCache) Set

func (m *MemorySessionCache) Set(ctx context.Context, key string, value []byte, opt ...sessions.SessionStoreOption) error

func (*MemorySessionCache) SetMany

func (m *MemorySessionCache) SetMany(ctx context.Context, values map[string][]byte, opt ...sessions.SessionStoreOption) error

type NoOpSessionStore added in v0.5.7

type NoOpSessionStore struct{}

Don't panic in dev (ideally).

func (*NoOpSessionStore) Clear added in v0.5.7

func (*NoOpSessionStore) Delete added in v0.5.7

func (*NoOpSessionStore) Get added in v0.5.7

func (*NoOpSessionStore) GetAll added in v0.5.7

func (n *NoOpSessionStore) GetAll(ctx context.Context, pageToken string, opt ...sessions.SessionStoreOption) (map[string][]byte, string, error)

func (*NoOpSessionStore) GetMany added in v0.5.7

func (n *NoOpSessionStore) GetMany(ctx context.Context, keys []string, opt ...sessions.SessionStoreOption) (map[string][]byte, []string, error)

func (*NoOpSessionStore) Set added in v0.5.7

func (n *NoOpSessionStore) Set(ctx context.Context, key string, value []byte, opt ...sessions.SessionStoreOption) error

func (*NoOpSessionStore) SetMany added in v0.5.7

func (n *NoOpSessionStore) SetMany(ctx context.Context, values map[string][]byte, opt ...sessions.SessionStoreOption) error

type SetManyable added in v0.5.3

type SetManyable[T any] interface {
	SetMany(ctx context.Context, values map[string]T, opt ...sessions.SessionStoreOption) error
}

type SetSessionStore added in v0.5.0

type SetSessionStore interface {
	SetSessionStore(ctx context.Context, store sessions.SessionStore)
}

type SizedItem added in v0.6.7

type SizedItem[T any] struct {
	Key   string
	Value T
	Size  int // size in bytes of key + value
}

SizedItem represents a key-value pair with its size in bytes.

type StringCodec added in v0.5.0

type StringCodec struct{}

func (*StringCodec) Decode added in v0.5.0

func (s *StringCodec) Decode(data []byte) (string, error)

func (*StringCodec) Encode added in v0.5.0

func (s *StringCodec) Encode(value string) ([]byte, error)

type TypedSessionCache added in v0.5.0

type TypedSessionCache[T any] struct {
	// contains filtered or unexported fields
}

func NewIntSessionCache added in v0.5.0

func NewIntSessionCache(cache sessions.SessionStore) *TypedSessionCache[int]

func NewJSONSessionCache added in v0.5.0

func NewJSONSessionCache[T any](cache sessions.SessionStore) *TypedSessionCache[T]

func NewStringSessionCache added in v0.5.0

func NewStringSessionCache(cache sessions.SessionStore) *TypedSessionCache[string]

func NewTypedSessionCache added in v0.5.0

func NewTypedSessionCache[T any](cache sessions.SessionStore, codec Codec[T]) *TypedSessionCache[T]

func (*TypedSessionCache[T]) Clear added in v0.5.0

func (*TypedSessionCache[T]) Delete added in v0.5.0

func (t *TypedSessionCache[T]) Delete(ctx context.Context, key string, opt ...sessions.SessionStoreOption) error

func (*TypedSessionCache[T]) Get added in v0.5.0

func (t *TypedSessionCache[T]) Get(ctx context.Context, key string, opt ...sessions.SessionStoreOption) (T, bool, error)

func (*TypedSessionCache[T]) GetAll added in v0.5.0

func (t *TypedSessionCache[T]) GetAll(ctx context.Context, pageToken string, opt ...sessions.SessionStoreOption) (map[string]T, string, error)

func (*TypedSessionCache[T]) GetMany added in v0.5.0

func (t *TypedSessionCache[T]) GetMany(ctx context.Context, keys []string, opt ...sessions.SessionStoreOption) (map[string]T, []string, error)

func (*TypedSessionCache[T]) Set added in v0.5.0

func (t *TypedSessionCache[T]) Set(ctx context.Context, key string, value T, opt ...sessions.SessionStoreOption) error

func (*TypedSessionCache[T]) SetMany added in v0.5.0

func (t *TypedSessionCache[T]) SetMany(ctx context.Context, values map[string]T, opt ...sessions.SessionStoreOption) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL