session

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: Apache-2.0 Imports: 20 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

This section is empty.

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 NewGRPCSessionCache added in v0.5.0

NewGRPCSessionCache creates a new gRPC session cache instance.

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 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

Types

type Codec added in v0.5.0

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

type GRPCSessionCache added in v0.5.0

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

func (*GRPCSessionCache) Clear added in v0.5.0

Clear removes all values from the cache.

func (*GRPCSessionCache) Delete added in v0.5.0

Delete removes a value from the cache by key.

func (*GRPCSessionCache) Get added in v0.5.0

Get retrieves a value from the cache by key.

func (*GRPCSessionCache) GetAll added in v0.5.0

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

GetAll returns all key-value pairs. Note: The gRPC service doesn't have a GetAll method, so we'll need to implement this by getting all keys first and then using GetMany. This is a limitation of the current gRPC service definition.

func (*GRPCSessionCache) GetMany added in v0.5.0

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

GetMany retrieves multiple values from the cache by keys.

func (*GRPCSessionCache) Set added in v0.5.0

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

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

func (*GRPCSessionCache) SetMany added in v0.5.0

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

SetMany stores multiple values in the cache.

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 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 SetSessionStore added in v0.5.0

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

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, opt ...sessions.SessionStoreOption) (map[string]T, 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, 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