adapter API

adapter

package

API reference for the adapter package.

I
interface

Store

Store abstracts the primary storage used as fallback and warmup source.

T represents the type of values stored in the adapter.

v1/adapter/adapter.go:11-20
type Store interface

Methods

Get
Method

Parameters

key string

Returns

T
bool
error
func Get(...)
Set
Method

Parameters

key string
value T

Returns

error
func Set(...)
Keys
Method

Parameters

Returns

[]string
error
func Keys(...)
I
interface

Batch

Batch allows grouping multiple operations before committing them to the
underlying storage.

v1/adapter/adapter.go:24-28
type Batch interface

Methods

Set
Method

Parameters

key string
value T

Returns

error
func Set(...)
Delete
Method

Parameters

key string

Returns

error
func Delete(...)
Commit
Method

Parameters

Returns

error
func Commit(...)
I
interface

Batcher

Batcher is implemented by stores that support batch operations.

v1/adapter/adapter.go:31-33
type Batcher interface

Methods

Batch
Method

Parameters

Returns

Batch[T]
error
func Batch(...)
S
struct

InMemoryStore

InMemoryStore is a simple Store implementation backed by a map.

v1/adapter/adapter.go:36-39
type InMemoryStore struct

Fields

Name Type Description
mu sync.RWMutex
items map[string]T
F
function

NewInMemoryStore

NewInMemoryStore returns a new InMemoryStore.

Returns

*InMemoryStore[T]
v1/adapter/adapter.go:42-44
func NewInMemoryStore[T any]() *InMemoryStore[T]

{
	return &InMemoryStore[T]{items: make(map[string]T)}
}
S
struct

inMemoryBatch

v1/adapter/adapter.go:82-86
type inMemoryBatch struct

Fields

Name Type Description
s *InMemoryStore[T]
sets map[string]T
deletes []string
S
struct

GormEntityStore

GormEntityStore implements Store by mapping keys directly to a GORM model’s primary key.
Unlike GormStore, which uses a KV table to store serialized blobs, GormEntityStore
operates directly on the entity table defined by T.

T should be a struct type that GORM recognizes as a model.

v1/adapter/gorm_entity_store.go:19-23
type GormEntityStore struct

Fields

Name Type Description
db *gorm.DB
keyColumn string
keyParser func(string) (any, error)
T
type

EntityOption

EntityOption configures a GormEntityStore.

v1/adapter/gorm_entity_store.go:26-26
type EntityOption func(*entityStoreOptions)
S
struct

entityStoreOptions

v1/adapter/gorm_entity_store.go:28-31
type entityStoreOptions struct

Fields

Name Type Description
keyColumn string
keyParser func(string) (any, error)
F
function

WithEntityKeyColumn

WithEntityKeyColumn sets the column name to use for lookups (default “id”).

Parameters

col
string

Returns

v1/adapter/gorm_entity_store.go:34-38
func WithEntityKeyColumn(col string) EntityOption

{
	return func(o *entityStoreOptions) {
		o.keyColumn = col
	}
}
F
function

WithEntityKeyParser

WithEntityKeyParser sets a function to convert the string key to the DB key type.
Default is to pass the string as-is.
Useful for integer primary keys: use adapter.ParseIntKey

Parameters

parser
func(string) (any, error)

Returns

v1/adapter/gorm_entity_store.go:43-47
func WithEntityKeyParser(parser func(string) (any, error)) EntityOption

{
	return func(o *entityStoreOptions) {
		o.keyParser = parser
	}
}
F
function

ParseIntKey

ParseIntKey is a helper for WithEntityKeyParser to convert keys to integers.

Parameters

s
string

Returns

any
error
v1/adapter/gorm_entity_store.go:50-52
func ParseIntKey(s string) (any, error)

{
	return strconv.Atoi(s)
}
F
function

NewGormEntityStore

NewGormEntityStore creates a new GormEntityStore.
T is the model struct.

Parameters

db
opts
...EntityOption

Returns

*GormEntityStore[T]
v1/adapter/gorm_entity_store.go:56-69
func NewGormEntityStore[T any](db *gorm.DB, opts ...EntityOption) *GormEntityStore[T]

{
	o := entityStoreOptions{
		keyColumn: "id",
		keyParser: func(s string) (any, error) { return s, nil },
	}
	for _, opt := range opts {
		opt(&o)
	}
	return &GormEntityStore[T]{
		db:        db,
		keyColumn: o.keyColumn,
		keyParser: o.keyParser,
	}
}
S
struct

gormEntityBatch

v1/adapter/gorm_entity_store.go:141-145
type gormEntityBatch struct

Fields

Name Type Description
s *GormEntityStore[T]
sets []T
deletes []any
S
struct

gormKV

gormKV is the internal model used to store key-value pairs in the database.

v1/adapter/gorm_store.go:20-23
type gormKV struct

Fields

Name Type Description
Key string gorm:"primaryKey;column:key_id"
Value []byte gorm:"column:value"
S
struct

GormStore

GormStore implements Store using a GORM backend.

v1/adapter/gorm_store.go:26-31
type GormStore struct

Fields

Name Type Description
db *gorm.DB
tableName string
timeout time.Duration
codec cache.Codec
T
type

GormOption

GormOption configures a GormStore.

v1/adapter/gorm_store.go:34-34
type GormOption func(*gormStoreOptions)
S
struct

gormStoreOptions

v1/adapter/gorm_store.go:36-40
type gormStoreOptions struct

Fields

Name Type Description
tableName string
timeout time.Duration
codec cache.Codec
F
function

WithGormTableName

WithGormTableName sets the table name for the GormStore.

Parameters

name
string

Returns

v1/adapter/gorm_store.go:43-47
func WithGormTableName(name string) GormOption

{
	return func(o *gormStoreOptions) {
		o.tableName = name
	}
}
F
function

WithGormTimeout

WithGormTimeout sets the operation timeout for GORM calls.

Parameters

Returns

v1/adapter/gorm_store.go:50-54
func WithGormTimeout(d time.Duration) GormOption

{
	return func(o *gormStoreOptions) {
		o.timeout = d
	}
}
F
function

WithGormCodec

WithGormCodec sets the codec for serialization.

Parameters

Returns

v1/adapter/gorm_store.go:57-61
func WithGormCodec(c cache.Codec) GormOption

{
	return func(o *gormStoreOptions) {
		o.codec = c
	}
}
F
function

NewGormStore

NewGormStore returns a new GormStore using the provided GORM DB connection.

Parameters

db
opts
...GormOption

Returns

*GormStore[T]
v1/adapter/gorm_store.go:64-85
func NewGormStore[T any](db *gorm.DB, opts ...GormOption) *GormStore[T]

{
	o := gormStoreOptions{
		tableName: defaultGormTableName,
		timeout:   defaultGormOpTimeout,
		codec:     cache.GobCodec{},
	}
	for _, opt := range opts {
		opt(&o)
	}

	// Ensure the table exists
	if !db.Migrator().HasTable(o.tableName) {
		_ = db.Table(o.tableName).AutoMigrate(&gormKV{})
	}

	return &GormStore[T]{
		db:        db,
		tableName: o.tableName,
		timeout:   o.timeout,
		codec:     o.codec,
	}
}
S
struct

gormBatch

v1/adapter/gorm_store.go:191-195
type gormBatch struct

Fields

Name Type Description
s *GormStore[T]
sets map[string]T
deletes []string
S
struct

RedisStore

RedisStore implements Store using a Redis backend.

v1/adapter/redis_store.go:16-20
type RedisStore struct

Fields

Name Type Description
client *redis.Client
timeout time.Duration
codec cache.Codec
T
type

RedisOption

RedisOption configures a RedisStore.

v1/adapter/redis_store.go:23-23
type RedisOption func(*redisStoreOptions)
S
struct

redisStoreOptions

v1/adapter/redis_store.go:25-28
type redisStoreOptions struct

Fields

Name Type Description
timeout time.Duration
codec cache.Codec
F
function

WithTimeout

WithTimeout sets the operation timeout for Redis calls.

Parameters

Returns

v1/adapter/redis_store.go:31-35
func WithTimeout(d time.Duration) RedisOption

{
	return func(o *redisStoreOptions) {
		o.timeout = d
	}
}
F
function

WithCodec

WithCodec sets the codec for serialization.

Parameters

Returns

v1/adapter/redis_store.go:38-42
func WithCodec(c cache.Codec) RedisOption

{
	return func(o *redisStoreOptions) {
		o.codec = c
	}
}
F
function

NewRedisStore

NewRedisStore returns a new RedisStore using the provided Redis client.

Parameters

client
opts
...RedisOption

Returns

*RedisStore[T]
v1/adapter/redis_store.go:45-54
func NewRedisStore[T any](client *redis.Client, opts ...RedisOption) *RedisStore[T]

{
	o := redisStoreOptions{
		timeout: defaultRedisOpTimeout,
		codec:   cache.GobCodec{},
	}
	for _, opt := range opts {
		opt(&o)
	}
	return &RedisStore[T]{client: client, timeout: o.timeout, codec: o.codec}
}
S
struct

redisBatch

v1/adapter/redis_store.go:162-166
type redisBatch struct

Fields

Name Type Description
s *RedisStore[T]
sets map[string]T
deletes []string