sqlite

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidPath is returned when Path is empty.
	ErrInvalidPath = errors.New("sqlite: Path must not be empty")

	// ErrInvalidMaxOpenConns is returned when MaxOpenConns is < 0.
	ErrInvalidMaxOpenConns = errors.New("sqlite: MaxOpenConns must be >= 0")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Path is the path to the SQLite database file (REQUIRED, must not be empty).
	// Use ":memory:" for in-memory database.
	Path string

	// MaxOpenConns is the maximum number of open connections to the database (OPTIONAL).
	// Default: 1 (recommended for SQLite to avoid lock contention)
	// Set to 0 for unlimited connections (not recommended for SQLite).
	MaxOpenConns int

	// CleanupInterval is the interval for cleaning up expired entries (OPTIONAL).
	// Default: 1 minute
	// Set to negative value to disable automatic cleanup.
	CleanupInterval time.Duration

	// WALMode enables Write-Ahead Logging mode for better concurrency (OPTIONAL).
	// Default: true
	// Set to false to use default journal mode (not recommended).
	WALMode *bool
}

Config holds configuration for SQLiteStore.

type SQLiteStore

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

SQLiteStore is a SQLite-backed cache store. Thread-safe for concurrent use with WAL mode enabled.

Reference: .references/gookit-cache/boltdb/boltdb.go (embedded database operations)

func New

func New(cfg Config) (*SQLiteStore, error)

New creates a new SQLiteStore with the given configuration.

func (*SQLiteStore) Clear

func (s *SQLiteStore) Clear(ctx context.Context) error

Clear removes all entries from SQLite.

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

Close releases resources associated with the SQLite database. Idempotent - safe to call multiple times.

func (*SQLiteStore) Delete

func (s *SQLiteStore) Delete(ctx context.Context, key string) error

Delete removes a value from SQLite. Idempotent - deleting a non-existent key returns nil.

func (*SQLiteStore) Get

func (s *SQLiteStore) Get(ctx context.Context, key string) ([]byte, error)

Get retrieves a value from SQLite by key. Returns cache.ErrNotFound if the key doesn't exist or has expired.

func (*SQLiteStore) Set

func (s *SQLiteStore) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

Set stores a value in SQLite with the specified TTL.

TTL semantics: - ttl == 0: no expiration - ttl < 0: no expiration - ttl > 0: expires after the specified duration

Jump to

Keyboard shortcuts

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