cache

package
v0.0.0-...-8137617 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2025 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterHeaders

func FilterHeaders(headers map[string][]string) map[string][]string

FilterHeaders 过滤不需要缓存的响应头

Types

type Cache

type Cache interface {
	Get(key string) (*CacheItem, error)
	Set(key string, value *CacheItem, ttl int) error
	Delete(key string) error
	Close() error
}

Cache interface defines methods for cache operations 缓存接口定义了缓存操作的方法

type CacheItem

type CacheItem struct {
	Body    []byte              `json:"body"`
	Headers map[string][]string `json:"headers"`
}

CacheItem 结构体保持不变,但在存储时使用过滤后的头部

type CacheManager

type CacheManager struct {
	// contains filtered or unexported fields
}

CacheManager manages cache operations and provides a unified interface 缓存管理器管理缓存操作并提供统一接口

func NewCacheManager

func NewCacheManager(config config.Cache) (*CacheManager, error)

NewCacheManager creates a new cache manager based on configuration 根据配置创建新的缓存管理器

func (*CacheManager) Close

func (m *CacheManager) Close() error

Close cleans up resources used by the cache 清理缓存使用的资源

func (*CacheManager) Delete

func (m *CacheManager) Delete(key string) error

Delete removes a value from the cache by key 通过键从缓存中删除值

func (*CacheManager) Get

func (m *CacheManager) Get(key string) (*CacheItem, error)

Get retrieves a value from the cache by key 通过键从缓存获取值

func (*CacheManager) Set

func (m *CacheManager) Set(key string, value *CacheItem, ttl int) error

Set stores a value in the cache with the given key and TTL 将值存储在缓存中,使用给定的键和TTL

type MemoryCache

type MemoryCache struct {
	// contains filtered or unexported fields
}

MemoryCache implements Cache interface using in-memory storage 内存缓存实现了使用内存存储的缓存接口

func NewMemoryCache

func NewMemoryCache() *MemoryCache

NewMemoryCache creates a new memory cache instance 创建一个新的内存缓存实例

func (*MemoryCache) Close

func (c *MemoryCache) Close() error

Close cleans up resources used by the cache 清理缓存使用的资源

func (*MemoryCache) Delete

func (c *MemoryCache) Delete(key string) error

Delete removes a value from the cache by key 通过键从缓存中删除值

func (*MemoryCache) Get

func (c *MemoryCache) Get(key string) (*CacheItem, error)

Get retrieves a value from the cache by key 通过键从缓存中获取值

func (*MemoryCache) Set

func (c *MemoryCache) Set(key string, value *CacheItem, ttl int) error

Set stores a value in the cache with the given key and TTL 将值存储在缓存中,使用给定的键和TTL

type RedisCache

type RedisCache struct {
	// contains filtered or unexported fields
}

RedisCache implements Cache interface using Redis Redis缓存实现了使用Redis的缓存接口

func NewRedisCache

func NewRedisCache(config config.Cache) (*RedisCache, error)

NewRedisCache creates a new Redis cache instance 创建一个新的Redis缓存实例

func (*RedisCache) Close

func (c *RedisCache) Close() error

Close closes the Redis client connection 关闭Redis客户端连接

func (*RedisCache) Delete

func (c *RedisCache) Delete(key string) error

Delete removes a value from Redis by key 通过键从Redis中删除值

func (*RedisCache) Get

func (c *RedisCache) Get(key string) (*CacheItem, error)

Get retrieves a value from Redis by key 通过键从Redis获取值

func (*RedisCache) Set

func (c *RedisCache) Set(key string, value *CacheItem, ttl int) error

Set stores a value in Redis with the given key and TTL 将值存储在Redis中,使用给定的键和TTL

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL