Documentation
¶
Overview ¶
Package storage implements flexible storage backends with interface abstractions.
Package storage implements SQLite storage provider.
Index ¶
- Variables
- type CompositeProvider
- func (c *CompositeProvider) Clear(ctx context.Context) error
- func (c *CompositeProvider) Close(ctx context.Context) error
- func (c *CompositeProvider) Delete(ctx context.Context, key string) error
- func (c *CompositeProvider) Exists(ctx context.Context, key string) (bool, error)
- func (c *CompositeProvider) GetStats(ctx context.Context) (*Stats, error)
- func (c *CompositeProvider) GetTTL(ctx context.Context, key string) (*time.Duration, error)
- func (c *CompositeProvider) Load(ctx context.Context, key string) (interface{}, error)
- func (c *CompositeProvider) Save(ctx context.Context, key string, value interface{}, ttl *time.Duration) error
- func (c *CompositeProvider) SetTTL(ctx context.Context, key string, ttl time.Duration) error
- type Entry
- type Error
- type Event
- type EventHandler
- type EventType
- type Manager
- func (sm *Manager) CloseAll(ctx context.Context) error
- func (sm *Manager) CreateProvider(ctx context.Context, name string, factoryName string, options Options) error
- func (sm *Manager) GetProvider(name string) (Provider, error)
- func (sm *Manager) GetStats(ctx context.Context) (map[string]*Stats, error)
- func (sm *Manager) ListProviders() []string
- func (sm *Manager) RegisterFactory(name string, factory ProviderFactory)
- func (sm *Manager) RemoveProvider(ctx context.Context, name string) error
- type Options
- type Provider
- type ProviderFactory
- type SQLiteStorage
- func (s *SQLiteStorage) AddEventHandler(handler EventHandler)
- func (s *SQLiteStorage) Clear(ctx context.Context) error
- func (s *SQLiteStorage) Close(_ context.Context) error
- func (s *SQLiteStorage) Delete(ctx context.Context, key string) error
- func (s *SQLiteStorage) Exists(ctx context.Context, key string) (bool, error)
- func (s *SQLiteStorage) GetStats(ctx context.Context) (*Stats, error)
- func (s *SQLiteStorage) GetTTL(ctx context.Context, key string) (*time.Duration, error)
- func (s *SQLiteStorage) Load(ctx context.Context, key string) (interface{}, error)
- func (s *SQLiteStorage) Save(ctx context.Context, key string, value interface{}, ttl *time.Duration) error
- func (s *SQLiteStorage) SetTTL(ctx context.Context, key string, ttl time.Duration) error
- type SQLiteStorageEntry
- type SQLiteStorageFactory
- type Stats
Constants ¶
This section is empty.
Variables ¶
var ErrNoTTL = errors.New("no TTL set")
ErrNoTTL is returned when no TTL is set for a key
Functions ¶
This section is empty.
Types ¶
type CompositeProvider ¶
type CompositeProvider struct {
// contains filtered or unexported fields
}
CompositeProvider combines multiple storage providers
func NewCompositeProvider ¶
func NewCompositeProvider(primary Provider, fallback Provider) *CompositeProvider
NewCompositeProvider creates a new composite storage provider
func (*CompositeProvider) Clear ¶
func (c *CompositeProvider) Clear(ctx context.Context) error
Clear implements Provider.Clear
func (*CompositeProvider) Close ¶
func (c *CompositeProvider) Close(ctx context.Context) error
Close implements Provider.Close
func (*CompositeProvider) Delete ¶
func (c *CompositeProvider) Delete(ctx context.Context, key string) error
Delete implements Provider.Delete
func (*CompositeProvider) GetStats ¶
func (c *CompositeProvider) GetStats(ctx context.Context) (*Stats, error)
GetStats implements Provider.GetStats
func (*CompositeProvider) Load ¶
func (c *CompositeProvider) Load(ctx context.Context, key string) (interface{}, error)
Load implements Provider.Load with fallback
type Entry ¶
type Entry struct {
Key string `json:"key"`
Value interface{} `json:"value"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
Size int64 `json:"size_bytes"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
Entry represents a stored value with metadata
type Error ¶
type Error struct {
Op string `json:"operation"`
Key string `json:"key"`
Message string `json:"message"`
Code string `json:"error_code"`
}
Error represents storage-specific errors
type Event ¶
type Event struct {
Type EventType `json:"type"`
Key string `json:"key"`
Timestamp time.Time `json:"timestamp"`
Data interface{} `json:"data,omitempty"`
}
Event represents storage lifecycle events
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages multiple storage providers
func (*Manager) CreateProvider ¶
func (sm *Manager) CreateProvider(ctx context.Context, name string, factoryName string, options Options) error
CreateProvider creates a storage provider using a registered factory
func (*Manager) GetProvider ¶
GetProvider returns a storage provider by name GetProvider returns a provider by name
func (*Manager) ListProviders ¶
ListProviders returns a list of all provider names
func (*Manager) RegisterFactory ¶
func (sm *Manager) RegisterFactory(name string, factory ProviderFactory)
RegisterFactory registers a storage provider factory
type Options ¶
type Options struct {
DefaultTTL *time.Duration `json:"default_ttl"`
MaxKeys int64 `json:"max_keys"`
MaxSize int64 `json:"max_size_bytes"`
CleanupInterval time.Duration `json:"cleanup_interval"`
Compression bool `json:"compression"`
Encryption bool `json:"encryption"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
Options configures storage behavior
type Provider ¶
type Provider interface {
// Save stores a value with an optional TTL
Save(ctx context.Context, key string, value interface{}, ttl *time.Duration) error
// Load retrieves a value by key
Load(ctx context.Context, key string) (interface{}, error)
// Delete removes a value by key
Delete(ctx context.Context, key string) error
// Exists checks if a key exists
Exists(ctx context.Context, key string) (bool, error)
// GetTTL returns the remaining TTL for a key
GetTTL(ctx context.Context, key string) (*time.Duration, error)
// SetTTL updates the TTL for a key
SetTTL(ctx context.Context, key string, ttl time.Duration) error
// Clear removes all data from storage
Clear(ctx context.Context) error
// GetStats returns storage statistics
GetStats(ctx context.Context) (*Stats, error)
// Close closes the storage provider
Close(ctx context.Context) error
}
Provider defines the interface for storage backends.
type ProviderFactory ¶
type ProviderFactory interface {
// Create creates a new storage provider with the given options
Create(ctx context.Context, options Options) (Provider, error)
// GetType returns the type of storage provider this factory creates
GetType() string
}
ProviderFactory creates storage providers
type SQLiteStorage ¶
type SQLiteStorage struct {
// contains filtered or unexported fields
}
SQLiteStorage implements Provider using SQLite
func NewSQLiteStorage ¶
func NewSQLiteStorage(dbPath string, options Options) (*SQLiteStorage, error)
NewSQLiteStorage creates a new SQLite storage provider
func (*SQLiteStorage) AddEventHandler ¶
func (s *SQLiteStorage) AddEventHandler(handler EventHandler)
AddEventHandler adds an event handler
func (*SQLiteStorage) Clear ¶
func (s *SQLiteStorage) Clear(ctx context.Context) error
Clear removes all data from storage
func (*SQLiteStorage) Close ¶
func (s *SQLiteStorage) Close(_ context.Context) error
Close closes the storage provider
func (*SQLiteStorage) Delete ¶
func (s *SQLiteStorage) Delete(ctx context.Context, key string) error
Delete removes a value by key
func (*SQLiteStorage) GetStats ¶
func (s *SQLiteStorage) GetStats(ctx context.Context) (*Stats, error)
GetStats returns storage statistics
func (*SQLiteStorage) Load ¶
func (s *SQLiteStorage) Load(ctx context.Context, key string) (interface{}, error)
Load retrieves a value by key
type SQLiteStorageEntry ¶
type SQLiteStorageEntry struct {
Key string `json:"key"`
Value []byte `json:"value"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
Size int64 `json:"size_bytes"`
Metadata []byte `json:"metadata,omitempty"`
}
SQLiteStorageEntry represents a storage entry in SQLite
type SQLiteStorageFactory ¶
type SQLiteStorageFactory struct{}
SQLiteStorageFactory implements StorageProviderFactory
func NewSQLiteStorageFactory ¶
func NewSQLiteStorageFactory() *SQLiteStorageFactory
NewSQLiteStorageFactory creates a new SQLite storage factory
func (*SQLiteStorageFactory) Create ¶
Create creates a new SQLite storage provider Create creates a new sqlite provider from options
func (*SQLiteStorageFactory) GetType ¶
func (f *SQLiteStorageFactory) GetType() string
GetType returns the type of storage provider
type Stats ¶
type Stats struct {
TotalKeys int64 `json:"total_keys"`
TotalSize int64 `json:"total_size_bytes"`
ExpiredKeys int64 `json:"expired_keys"`
MemoryUsage int64 `json:"memory_usage_bytes"`
LastCleanup time.Time `json:"last_cleanup"`
ProviderType string `json:"provider_type"`
}
Stats provides information about storage usage