session

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: Apache-2.0 Imports: 7 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

View Source
const KeyPrefixDelimiter = "::"

KeyPrefixDelimiter is the delimiter used to separate prefixes from keys in the session cache.

Variables

This section is empty.

Functions

func ClearJSON

func ClearJSON(ctx context.Context, opt ...types.SessionCacheOption) error

func DeleteJSON

func DeleteJSON(ctx context.Context, key string, opt ...types.SessionCacheOption) error

func GetAllJSON

func GetAllJSON[T any](ctx context.Context, opt ...types.SessionCacheOption) (map[string]T, error)

func GetJSON

func GetJSON[T any](ctx context.Context, key string, opt ...types.SessionCacheOption) (T, bool, error)

func GetManyJSON

func GetManyJSON[T any](ctx context.Context, keys []string, opt ...types.SessionCacheOption) (map[string]T, error)

func GetSession

func GetSession(ctx context.Context) (types.SessionCache, error)

GetSession retrieves the session cache instance from the context. Returns an error if no session cache is found in the context.

func GetSyncIDFromContext

func GetSyncIDFromContext(ctx context.Context) string

GetSyncIDFromContext retrieves the sync ID from the context, returning empty string if not found.

func NewMemorySessionCache

func NewMemorySessionCache(ctx context.Context, opt ...types.SessionCacheConstructorOption) (types.SessionCache, error)

NewMemorySessionCache creates a new in-memory session cache with default TTL of 1 hour.

func NewMemorySessionCacheWithTTL

func NewMemorySessionCacheWithTTL(ctx context.Context, ttl time.Duration, opt ...types.SessionCacheConstructorOption) (types.SessionCache, error)

NewMemorySessionCacheWithTTL creates a new in-memory session cache with custom TTL.

func SetJSON

func SetJSON[T any](ctx context.Context, key string, item T, opt ...types.SessionCacheOption) error

func SetManyJSON

func SetManyJSON[T any](ctx context.Context, items map[string]T, opt ...types.SessionCacheOption) error

func WithPrefix

func WithPrefix(prefix string) types.SessionCacheOption

func WithSyncID

func WithSyncID(syncID string) types.SessionCacheOption

Types

type MemorySessionCache

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

MemorySessionCache implements SessionCache interface using an in-memory store with TTL.

func (*MemorySessionCache) Clear

Clear removes all values from the cache.

func (*MemorySessionCache) Close

func (m *MemorySessionCache) Close(ctx context.Context) error

Close performs any necessary cleanup when the cache is no longer needed.

func (*MemorySessionCache) Delete

Delete removes a value from the cache by key.

func (*MemorySessionCache) Get

Get retrieves a value from the cache by key.

func (*MemorySessionCache) GetAll

func (m *MemorySessionCache) GetAll(ctx context.Context, opt ...types.SessionCacheOption) (map[string][]byte, error)

GetAll returns all key-value pairs.

func (*MemorySessionCache) GetMany

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

GetMany retrieves multiple values from the cache by keys.

func (*MemorySessionCache) Set

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

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

func (*MemorySessionCache) SetMany

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

SetMany stores multiple values in the cache.

Jump to

Keyboard shortcuts

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