Documentation
¶
Index ¶
- Variables
- type Data
- type Request
- func NewRawRequest(cfg *config.Cache, key, shard uint64, query, path []byte, headers [][2][]byte) *Request
- func NewRequest(cfg *config.Cache, path []byte, argsKvPairs [][2][]byte, ...) *Request
- func NewRequestFromFasthttp(cfg *config.Cache, r *fasthttp.RequestCtx) (*Request, error)
- func NewRequestFromNetHttp(cfg *config.Cache, r *http.Request) (*Request, error)
- 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) PrintDump()
- 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 ¶
var ( GzipBufferPool = &sync.Pool{New: func() any { return new(bytes.Buffer) }} GzipWriterPool = &sync.Pool{New: func() any { w, err := gzip.NewWriterLevel(nil, gzip.BestSpeed) if err != nil { panic("failed to Init. compress writer: " + err.Error()) } return w }} )
var (
RuleNotFoundError = errors.New("rule not found")
)
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 ¶
NewData creates a new Data object, compressing body with compress 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 NewRequestFromNetHttp ¶ added in v0.8.6
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.