Documentation
¶
Index ¶
- Variables
- func MatchRule(cfg config.Config, path []byte) *config.Rule
- func WetherAnErrIsTheRuleNotFound(err error) bool
- type CacheItem
- type Entry
- func EntryFromBytes(data []byte, cfg config.Config) (*Entry, error)
- func NewEntry(cfg config.Config, r *fasthttp.RequestCtx) (*Entry, error)
- func NewEntryFromField(key uint64, shard uint64, payload []byte, rule *config.Rule, updatedAt int64) *Entry
- func NewEntryWithPayload(cfg config.Config, req *fasthttp.Request, resp *fasthttp.Response) (*Entry, error)
- func (e *Entry) DumpBuffer(r *fasthttp.RequestCtx)
- func (e *Entry) Init() *Entry
- func (e *Entry) IsSamePayload(another *Entry) bool
- func (e *Entry) MapKey() uint64
- func (e *Entry) Payload() (req *fasthttp.Request, resp *fasthttp.Response, releaser Releaser, err error)
- func (e *Entry) PayloadBytes() []byte
- func (e *Entry) RefreshedAt() int64
- func (e *Entry) Release()
- func (e *Entry) ReleasePayload()
- func (e *Entry) Rule() *config.Rule
- func (e *Entry) SetMapKeyForTests(key uint64) *Entry
- func (e *Entry) SetPayload(req *fasthttp.Request, resp *fasthttp.Response) *Entry
- func (e *Entry) ShardKey() uint64
- func (e *Entry) ShouldBeRefreshed(cfg config.Config) bool
- func (e *Entry) SwapPayloads(another *Entry)
- func (e *Entry) ToBytes() (data []byte, releaseFn func())
- func (e *Entry) Touch()
- func (e *Entry) TouchRefreshedAt()
- func (e *Entry) TouchedAt() int64
- func (e *Entry) Weight() int64
- type Releaser
Constants ¶
This section is empty.
Variables ¶
var ( ErrPayloadIsEmpty = fmt.Errorf("payload is empty") ErrMalformedPayload = errors.New("malformed payload") )
Functions ¶
func WetherAnErrIsTheRuleNotFound ¶ added in v1.2.0
Types ¶
type CacheItem ¶ added in v1.2.0
type CacheItem interface {
Rule() *config.Rule
MapKey() uint64
ShardKey() uint64
SwapPayloads(another *Entry)
IsSamePayload(another *Entry) bool
SetPayload(req *fasthttp.Request, resp *fasthttp.Response) *Entry
Payload() (req *fasthttp.Request, resp *fasthttp.Response, releaser Releaser, err error)
ShouldBeRefreshed(cfg config.Config) bool
ToBytes() (data []byte, releaseFn func())
TouchRefreshedAt()
RefreshedAt() int64
TouchedAt() int64
Touch()
Weight() int64
}
type Entry ¶ added in v0.9.3
type Entry struct {
// contains filtered or unexported fields
}
func EntryFromBytes ¶ added in v0.9.3
EntryFromBytes decodes Entry from the wire format described in ToBytes. Strict bounds checks are applied to prevent panics on malformed input.
Zero-copy semantics:
The returned Entry will reference the provided `data` slice for payload (and rulePath is used only for rule lookup). Ensure `data` remains valid for as long as the Entry may access the payload (or copy the payload in your constructor, if that is your policy).
func NewEntryFromField ¶ added in v0.9.3
func NewEntryWithPayload ¶ added in v1.2.0
func (*Entry) DumpBuffer ¶ added in v1.0.1
func (e *Entry) DumpBuffer(r *fasthttp.RequestCtx)
func (*Entry) IsSamePayload ¶ added in v1.0.1
func (*Entry) Payload ¶ added in v0.9.3
func (e *Entry) Payload() (req *fasthttp.Request, resp *fasthttp.Response, releaser Releaser, err error)
Payload decodes e.payload into new fasthttp.Request/Response instances. On error, releases any acquired objects, logs the stage and offset, and returns an error.
func (*Entry) PayloadBytes ¶ added in v0.9.3
func (*Entry) RefreshedAt ¶ added in v1.2.0
func (*Entry) ReleasePayload ¶ added in v1.4.0
func (e *Entry) ReleasePayload()
func (*Entry) SetMapKeyForTests ¶ added in v1.2.0
SetMapKeyForTests is really dangerous - must be used exclusively in tests.
func (*Entry) SetPayload ¶ added in v0.9.3
SetPayload packs and gzip-compresses the entire payload: Path, Query, QueryHeaders, StatusCode, ResponseHeaders, Body. SetPayload encodes (req, resp) into Entry storage using the protocol above. It precomputes the total size to minimize reallocations and writes lengths in LE.
Preconditions:
- e.payload must own the backing *[]byte for the lifetime of any decoded response (i.e., do NOT return this buffer to a pool while response is in use).
func (*Entry) ShouldBeRefreshed ¶ added in v0.9.3
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 (*Entry) SwapPayloads ¶ added in v1.0.1
func (*Entry) ToBytes ¶ added in v0.9.3
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 RefreshedAt() 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) TouchRefreshedAt ¶ added in v1.4.4
func (e *Entry) TouchRefreshedAt()