Documentation
¶
Index ¶
- Variables
- func AdminCacheKey(username string) string
- func AdminIDCacheKey(adminID uint) string
- func AdminRolesCacheKey(adminID uint) string
- func CacheKey(parts ...string) string
- func GameCacheKey(gameID uint) string
- func GamesCacheKey() string
- func IsCacheMiss(err error) bool
- func PermissionCacheKey(permissionID string) string
- func RoleCacheKey(roleID uint) string
- func RolePermissionsCacheKey(roleID uint) string
- type CacheError
- type CacheHelper
- func (h *CacheHelper) GetJSON(ctx context.Context, key string, dest interface{}) error
- func (h *CacheHelper) Remember(ctx context.Context, key string, ttl time.Duration, dest interface{}, ...) error
- func (h *CacheHelper) SetJSON(ctx context.Context, key string, value interface{}, ttl time.Duration) error
- type CacheStore
- type LocalCache
- func (c *LocalCache) Close() error
- func (c *LocalCache) Delete(ctx context.Context, key string) error
- func (c *LocalCache) DeletePattern(ctx context.Context, pattern string) error
- func (c *LocalCache) Exists(ctx context.Context, key string) (bool, error)
- func (c *LocalCache) Get(ctx context.Context, key string) ([]byte, error)
- func (c *LocalCache) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
- func (c *LocalCache) Stats() (itemCount int)
- type NullCache
- func (c *NullCache) Close() error
- func (c *NullCache) Delete(ctx context.Context, key string) error
- func (c *NullCache) DeletePattern(ctx context.Context, pattern string) error
- func (c *NullCache) Exists(ctx context.Context, key string) (bool, error)
- func (c *NullCache) Get(ctx context.Context, key string) ([]byte, error)
- func (c *NullCache) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
- type RedisCache
- func (c *RedisCache) Client() *redis.Client
- func (c *RedisCache) Close() error
- func (c *RedisCache) Delete(ctx context.Context, key string) error
- func (c *RedisCache) DeletePattern(ctx context.Context, pattern string) error
- func (c *RedisCache) Exists(ctx context.Context, key string) (bool, error)
- func (c *RedisCache) Get(ctx context.Context, key string) ([]byte, error)
- func (c *RedisCache) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrCacheMiss = &CacheError{Message: "cache miss"}
ErrCacheMiss 缓存未命中错误
Functions ¶
func AdminRolesCacheKey ¶
AdminRolesCacheKey 生成管理员角色缓存键
func PermissionCacheKey ¶
PermissionCacheKey 生成权限缓存键
func RolePermissionsCacheKey ¶
RolePermissionsCacheKey 生成角色权限缓存键
Types ¶
type CacheError ¶
type CacheError struct {
Message string
}
CacheError 缓存错误
func (*CacheError) Error ¶
func (e *CacheError) Error() string
type CacheHelper ¶
type CacheHelper struct {
// contains filtered or unexported fields
}
CacheHelper 缓存辅助函数
func NewCacheHelper ¶
func NewCacheHelper(store CacheStore) *CacheHelper
func (*CacheHelper) GetJSON ¶
func (h *CacheHelper) GetJSON(ctx context.Context, key string, dest interface{}) error
GetJSON 从缓存获取 JSON 对象
type CacheStore ¶
type CacheStore interface {
// Get 获取缓存值
Get(ctx context.Context, key string) ([]byte, error)
// Set 设置缓存值
Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
// Delete 删除缓存
Delete(ctx context.Context, key string) error
// DeletePattern 删除匹配模式的所有缓存
DeletePattern(ctx context.Context, pattern string) error
// Exists 检查键是否存在
Exists(ctx context.Context, key string) (bool, error)
// Close 关闭缓存连接
Close() error
}
CacheStore 定义缓存接口
func NewCacheStore ¶
func NewCacheStore(cfg config.CacheConfig) (CacheStore, error)
NewCacheStore 根据配置创建缓存实例
type LocalCache ¶
type LocalCache struct {
// contains filtered or unexported fields
}
LocalCache 本地内存缓存实现(使用 go-cache,类似 Java Caffeine)
func NewLocalCache ¶
func NewLocalCache(defaultTTL, cleanupInterval time.Duration) *LocalCache
NewLocalCache 创建本地缓存实例
func (*LocalCache) Close ¶
func (c *LocalCache) Close() error
func (*LocalCache) DeletePattern ¶
func (c *LocalCache) DeletePattern(ctx context.Context, pattern string) error
type NullCache ¶
type NullCache struct{}
NullCache 空缓存实现(禁用缓存时使用)
func NewNullCache ¶
func NewNullCache() *NullCache
func (*NullCache) DeletePattern ¶
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache Redis 缓存实现
func NewRedisCache ¶
func NewRedisCache(addr, password string, db int, poolSize int, defaultTTL time.Duration) (*RedisCache, error)
NewRedisCache 创建 Redis 缓存实例
func (*RedisCache) Client ¶
func (c *RedisCache) Client() *redis.Client
Client 返回底层 Redis 客户端(用于高级操作)
func (*RedisCache) Close ¶
func (c *RedisCache) Close() error
func (*RedisCache) DeletePattern ¶
func (c *RedisCache) DeletePattern(ctx context.Context, pattern string) error
Click to show internal directories.
Click to hide internal directories.