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 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)
- type Cache
- 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) Forget(key string) error
- func (m *Manager) Get(key string) (interface{}, bool)
- func (m *Manager) GetString(key string) (string, 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) 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 ¶
View Source
const ( DriverMemory = "memory" DriverFile = "file" DriverRedis = "redis" DriverDatabase = "database" )
Driver types
Variables ¶
This section is empty.
Functions ¶
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
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 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 (*Manager) DefaultStore ¶
DefaultStore returns the default cache store
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
Click to show internal directories.
Click to hide internal directories.