Documentation
¶
Index ¶
- Constants
- func Decrement(key string, value int64) (int64, error)
- func Flush() error
- func Forever(key string, value interface{}) error
- func Forget(key string) error
- func Get(key string) (interface{}, bool)
- func GetString(key string) (string, bool)
- func Has(key string) bool
- func Increment(key string, value int64) (int64, error)
- func InitFromEnv() error
- func Initialize() error
- func Many(keys []string) map[string]interface{}
- func Put(key string, value interface{}, ttl time.Duration) error
- func PutMany(items map[string]interface{}, ttl time.Duration) error
- func Remember(key string, ttl time.Duration, callback func() interface{}) (interface{}, error)
- func RememberForever(key string, callback func() interface{}) (interface{}, error)
- func SetDefaultManager(m *Manager)
- func SetEventDispatcher(fn func(event interface{}) error)
- type Cache
- type CacheForgotten
- type CacheHit
- type CacheMiss
- type CacheWritten
- type Config
- type Manager
- func (m *Manager) Close() error
- func (m *Manager) Decrement(key string, value int64) (int64, error)
- func (m *Manager) DefaultStore() (Store, error)
- func (m *Manager) Flush() error
- func (m *Manager) Forever(key string, value interface{}) error
- func (m *Manager) ForeverWithContext(ctx context.Context, key string, value interface{}) error
- func (m *Manager) Forget(key string) error
- func (m *Manager) ForgetWithContext(ctx context.Context, key string) error
- func (m *Manager) Get(key string) (interface{}, bool)
- func (m *Manager) GetString(key string) (string, bool)
- func (m *Manager) GetWithContext(ctx context.Context, key string) (interface{}, bool)
- func (m *Manager) Has(key string) bool
- func (m *Manager) Increment(key string, value int64) (int64, error)
- func (m *Manager) Many(keys []string) map[string]interface{}
- func (m *Manager) Put(key string, value interface{}, ttl time.Duration) error
- func (m *Manager) PutMany(items map[string]interface{}, ttl time.Duration) error
- func (m *Manager) PutWithContext(ctx context.Context, key string, value interface{}, ttl time.Duration) error
- func (m *Manager) Remember(key string, ttl time.Duration, callback func() interface{}) (interface{}, error)
- func (m *Manager) RememberForever(key string, callback func() interface{}) (interface{}, error)
- func (m *Manager) Store(name string) (Store, error)
- type Store
- type StoreConfig
Constants ¶
const ( DriverMemory = "memory" DriverFile = "file" DriverRedis = "redis" DriverDatabase = "database" )
Driver types
Variables ¶
This section is empty.
Functions ¶
func InitFromEnv ¶ added in v0.9.5
func InitFromEnv() error
InitFromEnv sets up the cache manager with configuration from environment.
func Initialize ¶
func Initialize() error
Initialize sets up the cache manager with configuration from environment.
func RememberForever ¶
RememberForever gets from cache or computes and stores forever.
func SetDefaultManager ¶ added in v0.9.6
func SetDefaultManager(m *Manager)
SetDefaultManager sets the global default cache manager. Used by velocity.Default() to wire the App's cache into the global.
func SetEventDispatcher ¶ added in v0.4.0
func SetEventDispatcher(fn func(event interface{}) error)
SetEventDispatcher sets the function used to dispatch events. This is called by the events package to wire up event dispatching.
Types ¶
type Cache ¶
type Cache interface {
// Get retrieves a value from the cache
Get(key string) (interface{}, bool)
// GetString retrieves a string value from the cache
GetString(key string) (string, bool)
// Put stores a value in the cache with a TTL
Put(key string, value interface{}, ttl time.Duration) error
// Forever stores a value in the cache indefinitely
Forever(key string, value interface{}) error
// Forget removes a value from the cache
Forget(key string) error
// Flush removes all values from the cache
Flush() error
// Increment increments a numeric value
Increment(key string, value int64) (int64, error)
// Decrement decrements a numeric value
Decrement(key string, value int64) (int64, error)
// Remember gets from cache or computes and stores
Remember(key string, ttl time.Duration, callback func() interface{}) (interface{}, error)
// RememberForever gets from cache or computes and stores forever
RememberForever(key string, callback func() interface{}) (interface{}, error)
// Many retrieves multiple values
Many(keys []string) map[string]interface{}
// PutMany stores multiple values
PutMany(items map[string]interface{}, ttl time.Duration) error
// Has checks if a key exists
Has(key string) bool
}
Cache defines the interface for cache operations
type CacheForgotten ¶ added in v0.4.0
type CacheForgotten struct {
Context context.Context
Key string
Store string
TraceID string // APM trace ID
SpanID string // APM span ID
ParentID string // Parent span ID for correlation
}
CacheForgotten is dispatched when a key is removed from the cache
func (*CacheForgotten) Name ¶ added in v0.4.0
func (e *CacheForgotten) Name() string
Name returns the event name
type CacheHit ¶ added in v0.4.0
type CacheHit struct {
Context context.Context
Key string
Store string
TraceID string // APM trace ID
SpanID string // APM span ID
ParentID string // Parent span ID for correlation
}
CacheHit is dispatched when a cache lookup finds the key
type CacheMiss ¶ added in v0.4.0
type CacheMiss struct {
Context context.Context
Key string
Store string
TraceID string // APM trace ID
SpanID string // APM span ID
ParentID string // Parent span ID for correlation
}
CacheMiss is dispatched when a cache lookup does not find the key
type CacheWritten ¶ added in v0.4.0
type CacheWritten struct {
Context context.Context
Key string
Store string
TTL time.Duration // 0 means forever
TraceID string // APM trace ID
SpanID string // APM span ID
ParentID string // Parent span ID for correlation
}
CacheWritten is dispatched when a value is written to the cache
func (*CacheWritten) Name ¶ added in v0.4.0
func (e *CacheWritten) Name() string
Name returns the event name
type Config ¶
type Config struct {
Default string
Stores map[string]StoreConfig
Prefix string
}
Config holds cache configuration
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages multiple cache stores
func GetManager ¶
func GetManager() *Manager
GetManager returns the default cache manager, or nil if not initialized.
func NewManager ¶
NewManager creates a new cache manager with lazy store initialization.
func NewManagerFromConfig ¶ added in v0.9.5
NewManagerFromConfig creates a new cache manager and eagerly initializes all configured stores, returning an error if any store fails to initialize.
func (*Manager) DefaultStore ¶
DefaultStore returns the default cache store
func (*Manager) ForeverWithContext ¶ added in v0.4.0
ForeverWithContext stores a value in the default cache store indefinitely with context
func (*Manager) ForgetWithContext ¶ added in v0.4.0
ForgetWithContext removes a value from the default cache store with context
func (*Manager) GetWithContext ¶ added in v0.4.0
GetWithContext retrieves a value from the default cache store with context
func (*Manager) PutWithContext ¶ added in v0.4.0
func (m *Manager) PutWithContext(ctx context.Context, key string, value interface{}, ttl time.Duration) error
PutWithContext stores a value in the default cache store with context
func (*Manager) Remember ¶
func (m *Manager) Remember(key string, ttl time.Duration, callback func() interface{}) (interface{}, error)
Remember gets from default cache or computes and stores
func (*Manager) RememberForever ¶
RememberForever gets from default cache or computes and stores forever
type StoreConfig ¶
type StoreConfig struct {
Driver string
Prefix string
// Additional driver-specific config can be added here
Path string // For file driver
Host string // For Redis driver
Port int // For Redis driver
Password string // For Redis driver
Database int // For Redis driver
Table string // For database driver
}
StoreConfig holds configuration for a specific store