model

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMalformedOrNilPayload           = errors.New("malformed or nil payload")
	ErrCorruptedQueriesSection         = errors.New("corrupted queries section")
	ErrCorruptedRequestHeadersSection  = errors.New("corrupted request headers section")
	ErrCorruptedStatusCodeSection      = errors.New("corrupted status code section")
	ErrCorruptedResponseHeadersSection = errors.New("corrupted response headers section")
	ErrCorruptedResponseBodySection    = errors.New("corrupted response body section")
)
View Source
var ErrCacheRuleNotFound = errors.New("cache rule not found")

Functions

func IsCacheRuleNotFoundErr added in v1.8.0

func IsCacheRuleNotFoundErr(err error) bool

func MatchCacheRule added in v1.8.0

func MatchCacheRule(cfg config.Config, path []byte) (*config.Rule, error)

Types

type CacheItem added in v1.2.0

type CacheItem interface {
	CacheRule() *config.Rule
	Key() uint64
	SwapPayloads(another *Entry) int64
	IsTheSamePayload(another *Entry) bool
	SetPayload(queries, headers [][2][]byte, resp *fasthttp.Response)
	Payload() (queries, reqHeaders, rspHeaders [][2][]byte, body []byte, code int, releaser DecoderReleaser, err error)
	RequestPayload() (queries, headers [][2][]byte, releaser RequestDecoderReleaser, err error)
	ResponsePayload() (headers [][2][]byte, body []byte, code int, releaser ResponseDecoderReleaser, err error)
	IsProbablyExpired(cfg config.Config) bool
	ToBytes() (data []byte, releaseFn func())
	ClearRefreshQueued()
	TouchRefreshedAt()
	FreshAt() int64
	TouchedAt() int64
	Touch()
	Weight() int64
}

type DecoderReleaser added in v1.6.0

type DecoderReleaser func(queries, requestHeaders, responseHeaders [][2][]byte)

type Entry added in v0.9.3

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

func FromBytes added in v1.8.0

func FromBytes(data []byte, cfg config.Config) (*Entry, error)

FromBytes decodes Entry from the wire format described in ToBytes.

func NewEntry added in v1.2.0

func NewEntry(rule *config.Rule, queries, headers [][2][]byte) *Entry

func NewEntryFromField added in v0.9.3

func NewEntryFromField(
	key uint64,
	fHi uint64,
	fLo uint64,
	payload []byte,
	rule *config.Rule,
	updatedAt int64,
) *Entry

func NewMockEntryWithPayload added in v1.6.0

func NewMockEntryWithPayload(req *fasthttp.Request, resp *fasthttp.Response) (*Entry, error)

func (*Entry) CacheRule added in v1.8.0

func (e *Entry) CacheRule() *config.Rule

func (*Entry) ClearRefreshQueued added in v1.6.0

func (e *Entry) ClearRefreshQueued()

func (*Entry) DumpBuffer added in v1.0.1

func (e *Entry) DumpBuffer(r *fasthttp.RequestCtx)

func (*Entry) FreshAt added in v1.7.0

func (e *Entry) FreshAt() int64

func (*Entry) Init added in v0.9.3

func (e *Entry) Init() *Entry

func (*Entry) IsExpired added in v1.7.0

func (e *Entry) IsExpired(cfg config.Config) (must bool)

IsExpired - checks that elapsed time greater than TTL (used in hotpath: GET).

func (*Entry) IsProbablyExpired added in v1.7.0

func (e *Entry) IsProbablyExpired(cfg config.Config) bool

IsProbablyExpired implements probabilistic refresh logic ("beta" algorithm) and used while background refresh. Returns true if the entry is stale and, with a probability proportional to its staleness, should be refreshed now.

func (*Entry) IsTheSameFingerprint added in v1.6.0

func (e *Entry) IsTheSameFingerprint(in *Entry) bool

func (*Entry) IsTheSamePayload added in v1.6.0

func (e *Entry) IsTheSamePayload(another *Entry) bool

func (*Entry) Key added in v1.6.0

func (e *Entry) Key() uint64

func (*Entry) Payload added in v0.9.3

func (e *Entry) Payload() (queries, reqHeaders, rspHeaders [][2][]byte, body []byte, code int, releaser DecoderReleaser, err error)

func (*Entry) PayloadBytes added in v0.9.3

func (e *Entry) PayloadBytes() []byte

func (*Entry) Release added in v0.9.3

func (e *Entry) Release()

Release - should be released in cases when entry was not persisted

func (*Entry) ReleasePayload added in v1.4.0

func (e *Entry) ReleasePayload()

func (*Entry) RequestPayload added in v1.6.0

func (e *Entry) RequestPayload() (queries, headers [][2][]byte, releaser RequestDecoderReleaser, err error)

func (*Entry) ResponsePayload added in v1.6.0

func (e *Entry) ResponsePayload() (headers [][2][]byte, body []byte, code int, releaser ResponseDecoderReleaser, err error)

func (*Entry) SetMapKeyForTests added in v1.2.0

func (e *Entry) SetMapKeyForTests(key uint64) *Entry

SetMapKeyForTests is really dangerous - must be used exclusively in tests.

func (*Entry) SetPayload added in v0.9.3

func (e *Entry) SetPayload(queries, headers [][2][]byte, resp *fasthttp.Response)

func (*Entry) SwapPayloads added in v1.0.1

func (e *Entry) SwapPayloads(another *Entry) int64

func (*Entry) ToBytes added in v0.9.3

func (e *Entry) ToBytes() (data []byte, releaseFn func())

ToBytes encodes Entry into a compact little-endian binary format. Fingerprint is intentionally excluded from the wire format.

Layout (Little-Endian):

uint32  rulePathLen
[]byte  rulePath
uint64  key
uint64  shard
uint64  refreshedAtUnix // seconds or nanos — whatever FreshAt() returns
uint32  payloadLen
[]byte  payload

Notes:

  • Uses a pooled bytes.Buffer to minimize allocations.
  • No errors are returned; bytes.Buffer.Write never fails.
  • If Rule() is nil, this will panic (by design: Entry is assumed well-formed).

func (*Entry) ToMap added in v1.8.0

func (e *Entry) ToMap() map[string]any

func (*Entry) Touch added in v1.4.4

func (e *Entry) Touch()

func (*Entry) TouchRefreshedAt added in v1.4.4

func (e *Entry) TouchRefreshedAt()

func (*Entry) TouchedAt added in v1.4.4

func (e *Entry) TouchedAt() int64

func (*Entry) TryMarkRefreshQueued added in v1.6.0

func (e *Entry) TryMarkRefreshQueued() bool

func (*Entry) UnpackOffsets added in v1.6.0

func (e *Entry) UnpackOffsets(data []byte) (
	queriesOffset, reqHdrsOffset, statusOffset, rspHdrsOffset, bodyOffset int,
)

func (*Entry) UntouchRefreshedAt added in v1.8.0

func (e *Entry) UntouchRefreshedAt()

func (*Entry) WalkQuery added in v1.6.0

func (e *Entry) WalkQuery(fn func(key, value []byte) bool) error

WalkQuery iterates over query parameters directly from encoded payload. It never allocates and does not use fasthttp.Args. The callback gets raw slices of key and value (value may be nil if absent).

func (*Entry) Weight added in v0.9.3

func (e *Entry) Weight() int64

type RequestDecoderReleaser added in v1.6.0

type RequestDecoderReleaser func(queries, headers [][2][]byte)

type ResponseDecoderReleaser added in v1.6.0

type ResponseDecoderReleaser func(headers [][2][]byte)

Jump to

Keyboard shortcuts

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