cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Pass request status: pass
	Pass = iota + 1
	// Fetching request status: fetching
	Fetching
	// Waiting request status: wating
	Waiting
	// HitForPass request status: hitForPass
	HitForPass
	// Cacheable request status: cacheable
	Cacheable
)
View Source
const (
	// CompressMinLength the min length to gzip
	CompressMinLength = 1024
	// GzipEncoding gzip encoding
	GzipEncoding = "gzip"
	// BrEncoding br encoding
	BrEncoding = "br"
)

Variables

View Source
var (
	// ErrBodyCotentNotFound 无数据
	ErrBodyCotentNotFound = errors.New("content not found")
)
View Source
var StatusDescArr = []string{
	"",
	"pass",
	"fetching",
	"waiting",
	"hitForPass",
	"cacheable",
}

StatusDescArr status desc

Functions

This section is empty.

Types

type CachedResponse

type CachedResponse struct {
	Key       string `json:"key"`
	TTL       uint16 `json:"ttl"`
	CreatedAt uint32 `json:"createdAt"`
}

CachedResponse 缓存的请求

type Client

type Client struct {
	Path string

	sync.RWMutex
	// contains filtered or unexported fields
}

Client 缓存

func (*Client) Cacheable

func (c *Client) Cacheable(key []byte, ttl uint16)

Cacheable 设置状态为cacheable

func (*Client) ClearExpired

func (c *Client) ClearExpired(delay int)

ClearExpired 清除过期数据

func (*Client) Close

func (c *Client) Close() error

Close 关闭缓存

func (*Client) GetCachedList

func (c *Client) GetCachedList() []*CachedResponse

GetCachedList 获取缓存列表

func (*Client) GetFetchingList

func (c *Client) GetFetchingList() []*FetchingResponse

GetFetchingList 获取fetching的列表

func (*Client) GetRequestStatus

func (c *Client) GetRequestStatus(key []byte) (status int, ch chan int)

GetRequestStatus 获取key对应的请求status

func (*Client) GetResponse

func (c *Client) GetResponse(key []byte) (resp *Response, err error)

GetResponse 从缓存中获取Response

func (*Client) GetStats

func (c *Client) GetStats() (stats *Stats)

GetStats 获取缓存状态统计

func (*Client) HitForPass

func (c *Client) HitForPass(key []byte, ttl uint16)

HitForPass 设置为hit for pass

func (*Client) Init

func (c *Client) Init() error

Init 初始化缓存

func (*Client) Remove

func (c *Client) Remove(key []byte) error

Remove 删除缓存

func (*Client) SaveResponse

func (c *Client) SaveResponse(key []byte, resp *Response) error

SaveResponse 保存response

func (*Client) Size

func (c *Client) Size() int

Size 获取缓存数量

func (*Client) UpdateRequestStatus

func (c *Client) UpdateRequestStatus(key []byte, status int, ttl uint16)

UpdateRequestStatus 更新状态,获取等待中的请求,并设置状态和有效期

type FetchingResponse

type FetchingResponse struct {
	Key       string `json:"key"`
	CreatedAt uint32 `json:"createdAt"`
}

FetchingResponse fetching中的请求

type RequestStatus

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

RequestStatus 获取请求状态

type Response

type Response struct {
	// 创建时间
	CreatedAt uint32 `json:"createdAt"`
	// HTTP状态码
	StatusCode uint16 `json:"statusCode"`
	// 缓存有效时间(最大65535)
	TTL uint16 `json:"ttl"`
	// HTTP响应头
	Header http.Header `json:"header"`
	// HTTP响应数据
	Body []byte `json:"body"`
	// HTTP响应数据(gzip)
	GzipBody []byte `json:"gzip"`
	// HTTP响应数据(br)
	BrBody []byte `json:"br"`
	// 压缩数据级别
	CompressLevel int `json:"compressLevel"`
	// 最小压缩数据
	CompressMinLength int `json:"compressMinLength"`
}

Response 响应数据

func (*Response) GetBody

func (r *Response) GetBody(acceptEncoding string) (body []byte, encoding string)

GetBody 根据accept encondings 获取数据

type Stats

type Stats struct {
	Waiting    int `json:"waiting"`
	Fetching   int `json:"fetching"`
	HitForPass int `json:"hitForPass"`
	Cacheable  int `json:"cacheable"`
	FileSize   int `json:"fileSize"`
}

Stats 各状态数量统计

Jump to

Keyboard shortcuts

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