Documentation
¶
Index ¶
- Variables
- type Data
- type Request
- type Response
- func (r *Response) Body() []byte
- func (r *Response) Data() *Data
- func (r *Response) Headers() http.Header
- func (r *Response) Init() *Response
- func (r *Response) LruListElement() *list.Element[*Response]
- func (r *Response) MapKey() uint64
- func (r *Response) Request() *Request
- func (r *Response) Revalidate(ctx context.Context) error
- func (r *Response) RevalidatedAt() time.Time
- func (r *Response) SetLruListElement(el *list.Element[*Response])
- func (r *Response) SetUp(cfg *config.Cache, data *Data, req *Request, ...) *Response
- func (r *Response) ShardKey() uint64
- func (r *Response) ShouldBeRefreshed() bool
- func (r *Response) ToQuery() []byte
- func (r *Response) Touch() *Response
- func (r *Response) Weight() int64
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data struct {
// contains filtered or unexported fields
}
Data is the actual payload (status, h, body) stored in the cache.
func NewData ¶
func NewData(cfg *config.Cache, path []byte, statusCode int, headers http.Header, body []byte) *Data
NewData creates a new Data object, compressing body with gzip if large enough. Uses memory pools for buffer and writer to minimize allocations.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func NewRawRequest ¶
func NewRequest ¶
func NewRequestFromFasthttp ¶
func NewRequestFromFasthttp(cfg *config.Cache, r *fasthttp.RequestCtx) *Request
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response is the main cache object, holding the request, payload, metadata, and list pointers.
func NewResponse ¶
func NewResponse( data *Data, req *Request, cfg *config.Cache, revalidator func(ctx context.Context) (data *Data, err error), ) (*Response, error)
NewResponse constructs a new Response using memory pools and sets up all fields.
func (*Response) LruListElement ¶
LruListElement returns the LRU list element pointer (for LRU cache management).
func (*Response) Revalidate ¶
Revalidate calls the revalidator closure to fetch fresh data and updates the timestamp.
func (*Response) RevalidatedAt ¶
RevalidatedAt returns the last revalidation time (as time.Time).
func (*Response) SetLruListElement ¶
SetLruListElement sets the LRU list element pointer.
func (*Response) SetUp ¶
func (r *Response) SetUp( cfg *config.Cache, data *Data, req *Request, revalidator func(ctx context.Context) (data *Data, err error), ) *Response
SetUp stores the Data, Request, and config-driven fields into the Response.
func (*Response) ShouldBeRefreshed ¶
ShouldBeRefreshed implements probabilistic refresh logic ("beta" algorithm). Returns true if the entry is stale and, with a probability proportional to its staleness, should be refreshed now.