Documentation
¶
Index ¶
- type DatabaseSecondaryStorage
- func (storage *DatabaseSecondaryStorage) Close() error
- func (storage *DatabaseSecondaryStorage) Delete(ctx context.Context, key string) error
- func (storage *DatabaseSecondaryStorage) Get(ctx context.Context, key string) (any, error)
- func (storage *DatabaseSecondaryStorage) Incr(ctx context.Context, key string, ttl *time.Duration) (int, error)
- func (storage *DatabaseSecondaryStorage) Set(ctx context.Context, key string, value any, ttl *time.Duration) error
- func (storage *DatabaseSecondaryStorage) StartCleanup()
- type MemorySecondaryStorage
- func (storage *MemorySecondaryStorage) Close() error
- func (storage *MemorySecondaryStorage) Delete(ctx context.Context, key string) error
- func (storage *MemorySecondaryStorage) Get(ctx context.Context, key string) (any, error)
- func (storage *MemorySecondaryStorage) Incr(ctx context.Context, key string, ttl *time.Duration) (int, error)
- func (storage *MemorySecondaryStorage) Set(ctx context.Context, key string, value any, ttl *time.Duration) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DatabaseSecondaryStorage ¶ added in v1.3.0
type DatabaseSecondaryStorage struct {
// contains filtered or unexported fields
}
DatabaseSecondaryStorage implements the SecondaryStorage interface using GORM.
func NewDatabaseSecondaryStorage ¶ added in v1.3.0
func NewDatabaseSecondaryStorage(db *gorm.DB, config models.SecondaryStorageDatabaseOptions) *DatabaseSecondaryStorage
func (*DatabaseSecondaryStorage) Close ¶ added in v1.3.0
func (storage *DatabaseSecondaryStorage) Close() error
Close gracefully shuts down the storage by stopping the cleanup goroutine. This method is idempotent and safe to call multiple times.
func (*DatabaseSecondaryStorage) Delete ¶ added in v1.3.0
func (storage *DatabaseSecondaryStorage) Delete(ctx context.Context, key string) error
Delete removes a key from the database. It is idempotent: deleting a non-existent key does not return an error.
func (*DatabaseSecondaryStorage) Get ¶ added in v1.3.0
Get retrieves a value from the database by key. Returns nil if the key does not exist or has expired. Expired entries are deleted immediately to prevent database bloat.
func (*DatabaseSecondaryStorage) Incr ¶ added in v1.3.0
func (storage *DatabaseSecondaryStorage) Incr(ctx context.Context, key string, ttl *time.Duration) (int, error)
Incr increments the integer value stored at key by 1. If the key does not exist, it is initialized to 0 and then incremented to 1. If ttl is provided, it will be set or updated on the key. Expired entries are deleted immediately before incrementing.
func (*DatabaseSecondaryStorage) Set ¶ added in v1.3.0
func (storage *DatabaseSecondaryStorage) Set(ctx context.Context, key string, value any, ttl *time.Duration) error
Set stores a value in the database with an optional TTL. The value must be a string. If ttl is nil, the entry will not expire.
func (*DatabaseSecondaryStorage) StartCleanup ¶ added in v1.4.0
func (storage *DatabaseSecondaryStorage) StartCleanup()
StartCleanup starts the background cleanup goroutine that removes expired entries. This should be called after database migrations have completed. It is safe to call this multiple times - subsequent calls will be no-ops.
type MemorySecondaryStorage ¶ added in v1.3.0
type MemorySecondaryStorage struct {
// contains filtered or unexported fields
}
MemorySecondaryStorage is an in-memory implementation of SecondaryStorage.
func NewMemorySecondaryStorage ¶ added in v1.3.0
func NewMemorySecondaryStorage(config models.SecondaryStorageMemoryOptions) *MemorySecondaryStorage
func (*MemorySecondaryStorage) Close ¶ added in v1.3.0
func (storage *MemorySecondaryStorage) Close() error
Close gracefully shuts down the storage by stopping the cleanup goroutine. This method is idempotent and safe to call multiple times.
func (*MemorySecondaryStorage) Delete ¶ added in v1.3.0
func (storage *MemorySecondaryStorage) Delete(ctx context.Context, key string) error
Delete removes a key from storage. This operation is idempotent: no error is returned if the key does not exist.
func (*MemorySecondaryStorage) Get ¶ added in v1.3.0
Get retrieves a value from memory by key. Returns nil if the key does not exist or has expired. Expired entries are deleted immediately to prevent memory bloat.
func (*MemorySecondaryStorage) Incr ¶ added in v1.3.0
func (storage *MemorySecondaryStorage) Incr(ctx context.Context, key string, ttl *time.Duration) (int, error)
Incr increments the integer value stored at key by 1. If the key does not exist, it is initialized to 0 and then incremented to 1. If ttl is provided, it will be set or updated on the key. Expired entries are deleted immediately before incrementing.