model

package
v0.8.6 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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. gzip writer: " + err.Error())
		}
		return w
	}}
)

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.

func (*Data) Body

func (d *Data) Body() []byte

Body returns the response body (possibly gzip-compressed).

func (*Data) Headers

func (d *Data) Headers() http.Header

Headers returns the response h.

func (*Data) StatusCode

func (d *Data) StatusCode() int

StatusCode returns the HTTP status code.

func (*Data) Weight

func (d *Data) Weight() int64

type Request

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

func NewRawRequest

func NewRawRequest(cfg *config.Cache, key, shard uint64, query, path []byte) *Request

func NewRequest

func NewRequest(cfg *config.Cache, path []byte, args map[string][]byte, headers map[string][][]byte) *Request

func NewRequestFromFasthttp

func NewRequestFromFasthttp(cfg *config.Cache, r *fasthttp.RequestCtx) *Request

func NewRequestFromNetHttp added in v0.8.6

func NewRequestFromNetHttp(cfg *config.Cache, r *http.Request) *Request

func (*Request) MapKey

func (r *Request) MapKey() uint64

func (*Request) Path

func (r *Request) Path() []byte

func (*Request) ShardKey

func (r *Request) ShardKey() uint64

func (*Request) ToQuery

func (r *Request) ToQuery() []byte

func (*Request) Weight

func (r *Request) Weight() int64

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) Body

func (r *Response) Body() []byte

Body returns the response body.

func (*Response) Data

func (r *Response) Data() *Data

Data returns the underlying Data payload.

func (*Response) Headers

func (r *Response) Headers() http.Header

Headers returns the HTTP h.

func (*Response) Init

func (r *Response) Init() *Response

Init ensures all pointers are non-nil after pool Get.

func (*Response) LruListElement

func (r *Response) LruListElement() *list.Element[*Response]

LruListElement returns the LRU list element pointer (for LRU cache management).

func (*Response) MapKey

func (r *Response) MapKey() uint64

MapKey returns the key of the associated request.

func (*Response) Request

func (r *Response) Request() *Request

Request returns the request pointer.

func (*Response) Revalidate

func (r *Response) Revalidate(ctx context.Context) error

Revalidate calls the revalidator closure to fetch fresh data and updates the timestamp.

func (*Response) RevalidatedAt

func (r *Response) RevalidatedAt() time.Time

RevalidatedAt returns the last revalidation time (as time.Time).

func (*Response) SetLruListElement

func (r *Response) SetLruListElement(el *list.Element[*Response])

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) ShardKey

func (r *Response) ShardKey() uint64

ShardKey returns the shard key of the associated request.

func (*Response) ShouldBeRefreshed

func (r *Response) ShouldBeRefreshed() bool

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.

func (*Response) ToQuery

func (r *Response) ToQuery() []byte

ToQuery returns the query representation of the request.

func (*Response) Touch

func (r *Response) Touch() *Response

func (*Response) Weight

func (r *Response) Weight() int64

Weight estimates the in-memory size of this response (including dynamic fields).

Jump to

Keyboard shortcuts

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