model

package
v1.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data added in v0.3.0

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

Data is the actual payload (status, headers, body) stored in the cache.

func NewData added in v0.3.0

func NewData(statusCode int, headers http.Header, body []byte, releaseBody synced.FreeResourceFunc) *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 added in v0.3.0

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

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

func (*Data) Headers added in v0.3.0

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

Headers returns the response headers.

func (*Data) Release added in v0.7.0

func (d *Data) Release()

Release calls releaseFn and returns the Data to the pool.

func (*Data) StatusCode added in v0.3.0

func (d *Data) StatusCode() int

StatusCode returns the HTTP status code.

type Request

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

Request holds normalized, deduplicated, hashed and uniquely queryable representation of a cache request.

func NewManualRequest added in v0.3.1

func NewManualRequest(project, domain, language []byte, tags [][]byte) (*Request, error)

NewManualRequest creates a Request with explicit parameters, bypassing fasthttp.

func NewRequest

func NewRequest(q *fasthttp.Args) (*Request, error)

NewRequest builds a Request from fasthttp.Args, with strict interning and pooling.

func (*Request) GetDomain

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

func (*Request) GetLanguage

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

func (*Request) GetProject

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

Getters for all important fields.

func (*Request) GetTags added in v0.3.0

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

func (*Request) Key added in v0.7.0

func (r *Request) Key() uint64

Key returns the computed hash key for the request.

func (*Request) Release added in v0.7.0

func (r *Request) Release()

Release releases and resets the request (and any underlying buffer/tag slices) for reuse.

func (*Request) ShardKey added in v0.7.0

func (r *Request) ShardKey() uint64

ShardKey returns the precomputed shard index.

func (*Request) ToQuery added in v0.2.0

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

ToQuery returns the generated query string.

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.Config,
	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 added in v0.7.0

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

Body returns the response body.

func (*Response) CASRefCount added in v0.7.0

func (r *Response) CASRefCount(old, new int64) bool

CASRefCount performs a CAS on the refcount.

func (*Response) Data added in v0.7.0

func (r *Response) Data() *Data

Data returns the underlying Data payload.

func (*Response) DecRefCount added in v0.7.0

func (r *Response) DecRefCount() int64

DecRefCount decrements the refcount.

func (*Response) Headers added in v0.7.0

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

Headers returns the HTTP headers.

func (*Response) IncRefCount added in v0.7.0

func (r *Response) IncRefCount() int64

IncRefCount increments the refcount.

func (*Response) IsDoomed added in v0.7.0

func (r *Response) IsDoomed() bool

IsDoomed returns true if this object is scheduled for deletion.

func (*Response) Key added in v0.7.0

func (r *Response) Key() uint64

Key returns the key of the associated request.

func (*Response) LruListElement added in v0.7.0

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

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

func (*Response) MarkAsDoomed added in v0.7.0

func (r *Response) MarkAsDoomed() bool

MarkAsDoomed marks the response as scheduled for delete, only if not already doomed.

func (*Response) NativeRevalidateInterval added in v0.7.0

func (r *Response) NativeRevalidateInterval() int64

NativeRevalidateInterval returns the revalidation interval (as int64).

func (*Response) NativeRevalidatedAt added in v0.7.0

func (r *Response) NativeRevalidatedAt() int64

NativeRevalidatedAt returns the last revalidation time (as int64).

func (*Response) RefCount added in v0.7.0

func (r *Response) RefCount() int64

RefCount returns the current refcount.

func (*Response) Release added in v0.7.0

func (r *Response) Release() bool

Release releases the associated Data and Request, resets the Response, and returns it to the pool.

func (*Response) Request added in v0.7.0

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 added in v0.7.0

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

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

func (*Response) SetLruListElement added in v0.7.0

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

SetLruListElement sets the LRU list element pointer.

func (*Response) ShardKey added in v0.7.0

func (r *Response) ShardKey() uint64

ShardKey returns the shard key of the associated request.

func (*Response) ShardListElement added in v0.7.0

func (r *Response) ShardListElement() any

ShardListElement returns the LRU list element (for cache eviction).

func (*Response) ShouldRefresh added in v0.7.0

func (r *Response) ShouldRefresh() bool

ShouldRefresh 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) Size

func (r *Response) Size() uintptr

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

func (*Response) StoreRefCount added in v0.7.0

func (r *Response) StoreRefCount(new int64)

StoreRefCount stores a new refcount value directly.

func (*Response) StoreWheelListElement added in v1.1.0

func (r *Response) StoreWheelListElement(elem *list.Element[timemodel.Spoke])

StoreWheelListElement sets the wheel list element pointer.

func (*Response) ToQuery added in v0.7.0

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

ToQuery returns the query representation of the request.

func (*Response) WheelListElement added in v1.1.0

func (r *Response) WheelListElement() *list.Element[timemodel.Spoke]

WheelListElement returns the wheel list element pointer (for background refresh scheduling).

Jump to

Keyboard shortcuts

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