Documentation
¶
Index ¶
- Variables
- type Cache
- type Driver
- type FileDriver
- type Manager
- func (m *Manager) AddStore(name string, store *Store)
- 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) Has(key string) bool
- func (m *Manager) HasStore(name string) bool
- func (m *Manager) Put(key string, value interface{}, duration ...interface{}) error
- func (m *Manager) Remember(key string, duration interface{}, callback func() interface{}) (interface{}, error)
- func (m *Manager) RememberForever(key string, callback func() interface{}) (interface{}, error)
- func (m *Manager) RemoveStore(name string)
- func (m *Manager) Store(name ...string) *Store
- type MemoryDriver
- type RedisDriver
- func (d *RedisDriver) Clear() error
- func (d *RedisDriver) Close() error
- func (d *RedisDriver) Delete(key string) error
- func (d *RedisDriver) Get(key string) ([]byte, error)
- func (d *RedisDriver) GetClient() *redis.Client
- func (d *RedisDriver) Has(key string) bool
- func (d *RedisDriver) Put(key string, value []byte, duration time.Duration) error
- type Store
- func (s *Store) Add(key string, value interface{}, duration time.Duration) bool
- func (s *Store) Decrement(key string, value ...int64) (int64, error)
- func (s *Store) Flush() error
- func (s *Store) Forever(key string, value interface{}) error
- func (s *Store) Forget(key string) error
- func (s *Store) Get(key string) (interface{}, bool)
- func (s *Store) GetBool(key string) (bool, bool)
- func (s *Store) GetFloat(key string) (float64, bool)
- func (s *Store) GetInt(key string) (int64, bool)
- func (s *Store) GetMultiple(keys []string) map[string]interface{}
- func (s *Store) GetString(key string) (string, bool)
- func (s *Store) Has(key string) bool
- func (s *Store) Increment(key string, value ...int64) (int64, error)
- func (s *Store) Pull(key string) (interface{}, bool)
- func (s *Store) Put(key string, value interface{}, duration time.Duration) error
- func (s *Store) PutMultiple(values map[string]interface{}, duration time.Duration) error
- func (s *Store) Remember(key string, duration time.Duration, callback func() interface{}) (interface{}, error)
- func (s *Store) RememberForever(key string, callback func() interface{}) (interface{}, error)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrKeyNotFound = errors.New("cache: key not found") ErrInvalidType = errors.New("cache: invalid type") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
// Get 获取缓存值
Get(key string) (interface{}, bool)
// Put 设置缓存值(带过期时间)
Put(key string, value interface{}, duration time.Duration) error
// Forever 永久存储
Forever(key string, value interface{}) error
// Has 检查键是否存在
Has(key string) bool
// Forget 删除缓存
Forget(key string) error
// Flush 清空所有缓存
Flush() error
// Increment 增加数值
Increment(key string, value ...int64) (int64, error)
// Decrement 减少数值
Decrement(key string, value ...int64) (int64, error)
// Remember 如果不存在则创建并返回
Remember(key string, duration time.Duration, callback func() interface{}) (interface{}, error)
// RememberForever 永久记忆
RememberForever(key string, callback func() interface{}) (interface{}, error)
// Pull 获取并删除
Pull(key string) (interface{}, bool)
// Add 仅当键不存在时添加
Add(key string, value interface{}, duration time.Duration) bool
// GetMultiple 批量获取
GetMultiple(keys []string) map[string]interface{}
// PutMultiple 批量设置
PutMultiple(values map[string]interface{}, duration time.Duration) error
}
Cache 缓存接口
type Driver ¶
type Driver interface {
Get(key string) ([]byte, error)
Put(key string, value []byte, duration time.Duration) error
Delete(key string) error
Clear() error
Has(key string) bool
}
Driver 缓存驱动接口
type FileDriver ¶
type FileDriver struct {
// contains filtered or unexported fields
}
FileDriver 文件缓存驱动
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager 缓存管理器(支持多驱动)
func (*Manager) RememberForever ¶
type MemoryDriver ¶
type MemoryDriver struct {
// contains filtered or unexported fields
}
MemoryDriver 内存缓存驱动
type RedisDriver ¶
type RedisDriver struct {
// contains filtered or unexported fields
}
RedisDriver Redis 缓存驱动
func NewRedisDriver ¶
func NewRedisDriver(addr string, password string, db int) (*RedisDriver, error)
NewRedisDriver 创建 Redis 驱动
func NewRedisDriverWithClient ¶
func NewRedisDriverWithClient(client *redis.Client) *RedisDriver
NewRedisDriverWithClient 使用已有的 Redis 客户端创建驱动
func (*RedisDriver) GetClient ¶
func (d *RedisDriver) GetClient() *redis.Client
GetClient 获取原始 Redis 客户端
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store 缓存仓库
func (*Store) GetMultiple ¶
GetMultiple 批量获取
func (*Store) PutMultiple ¶
PutMultiple 批量设置
func (*Store) Remember ¶
func (s *Store) Remember(key string, duration time.Duration, callback func() interface{}) (interface{}, error)
Remember 如果不存在则创建并返回
func (*Store) RememberForever ¶
RememberForever 永久记忆
Click to show internal directories.
Click to hide internal directories.