Documentation
¶
Overview ¶
缓存空间功能, 将特定请求的响应缓存分类整理好 便于后续其他请求复用响应
Index ¶
Constants ¶
View Source
const ( // HeaderKeySpace 缓存空间 key HeaderKeySpace = "Space" // HeaderKeySpaceKey 缓存空间内部 key HeaderKeySpaceKey = "Space-Key" )
View Source
const (
// HeaderKeyExpired 缓存过期响应头, 用于覆盖默认的缓存过期时间
HeaderKeyExpired = "Expired"
)
Variables ¶
View Source
var CacheKeyIgnoreParams = map[string]struct{}{
"StartTimeTicks": {}, "X-Playback-Session-Id": {},
"PlaySessionId": {},
"Range": {}, "Host": {}, "Referrer": {}, "Connection": {},
"Accept": {}, "Accept-Encoding": {}, "Accept-Language": {}, "Cache-Control": {},
"Upgrade-Insecure-Requests": {}, "Referer": {}, "Origin": {}, "User-Agent": {},
"Pragma": {}, "Priority": {}, "Cookie": {},
"Sec-Fetch-Dest": {}, "Sec-Fetch-Mode": {}, "Sec-Fetch-Site": {},
"Sec-Ch-Ua": {}, "Sec-Ch-Ua-Mobile": {}, "Sec-Ch-Ua-Platform": {},
"Content-Type": {}, "Content-Length": {},
"X-Emby-Token": {}, "X-Emby-Authorization": {}, "Authorization": {},
"X-Emby-Device-Id": {}, "X-Emby-Device-Name": {},
"X-Emby-Client-IP": {}, "X-Real-IP": {}, "X-Forwarded-For": {},
"X-Forwarded-Proto": {}, "X-Forwarded-Host": {}, "X-Forwarded-Port": {},
"Via": {}, "X-Via": {},
"Cf-Ray": {}, "Cf-Visitor": {}, "Cf-Connecting-Ip": {}, "Cf-Ipcountry": {},
"Ali-Cdn-Real-Ip": {}, "Ali-Swift-Log-Host": {},
}
CacheKeyIgnoreParams 忽略的请求头或者参数
如果请求地址包含列表中的请求头或者参数, 则不参与 cacheKey 运算
View Source
var DefaultExpired = func() time.Duration { if config.C == nil || config.C.Cache == nil { return time.Hour * 24 } return config.C.Cache.ExpiredDuration() }
DefaultExpired 默认的请求过期时间
可通过设置 "Expired" 响应头进行覆盖
Functions ¶
func CacheableRouteMarker ¶
func CacheableRouteMarker() gin.HandlerFunc
CacheableRouteMarker 缓存白名单 只有匹配上正则表达式的路由才会被缓存
Types ¶
type RespCache ¶
type RespCache interface {
// Code 响应码
Code() int
// Body 克隆一个响应体, 转换为缓冲区
Body() *bytes.Buffer
// BodyBytes 克隆一个响应体
BodyBytes() []byte
// JsonBody 将响应体转化成 json 返回
JsonBody() (*jsons.Item, error)
// Header 获取响应头属性
Header(key string) string
// Headers 获取克隆响应头
Headers() http.Header
// Space 获取缓存空间名称
Space() string
// SpaceKey 获取缓存空间 key
SpaceKey() string
// Update 更新缓存
//
// code 传递零值时, 会自动忽略更新
//
// body 传递 nil 时, 会自动忽略更新,
// 传递空切片时, 会认为是一个空响应体进行更新
//
// header 传递 nil 时, 会自动忽略更新,
// 不为 nil 时, 缓存的响应头会被清空, 并设置为新值
Update(code int, body []byte, header http.Header)
}
RespCache 公开对外暴露的缓存接口
func GetSpaceCache ¶
GetSpaceCache 获取缓存空间的缓存对象
Click to show internal directories.
Click to hide internal directories.