config

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Prod = "prod"
	Dev  = "dev"
	Test = "test"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Cache CacheBox `yaml:"cache"`
}

func LoadConfig

func LoadConfig(path string) (*Cache, error)

func (*Cache) IsDev

func (c *Cache) IsDev() bool

func (*Cache) IsProd

func (c *Cache) IsProd() bool

func (*Cache) IsTest

func (c *Cache) IsTest() bool

type CacheBox

type CacheBox struct {
	Env         string           `yaml:"env"`
	Enabled     bool             `yaml:"enabled"`
	Logs        Logs             `yaml:"logs"`
	ForceGC     ForceGC          `yaml:"forceGC"`
	LifeTime    Lifetime         `yaml:"lifetime"`
	Upstream    Upstream         `yaml:"upstream"`
	Persistence Persistence      `yaml:"persistence"`
	Preallocate Preallocation    `yaml:"preallocate"`
	Eviction    Eviction         `yaml:"eviction"`
	Refresh     Refresh          `yaml:"refresh"`
	Storage     Storage          `yaml:"storage"`
	Rules       map[string]*Rule `yaml:"rules"`
}

type Dump

type Dump struct {
	IsEnabled    bool   `yaml:"enabled"`
	Format       string `yaml:"format"` // gzip or raw
	Dir          string `yaml:"dump_dir"`
	Name         string `yaml:"dump_name"`
	MaxFiles     int    `yaml:"max_files"`
	RotatePolicy string `yaml:"rotate_policy"` // fixed or ring
}

type Env

type Env struct {
	Value string `yaml:"value"`
}

type Eviction

type Eviction struct {
	Policy    string  `yaml:"policy"`    // at now, it's only "lru" + TinyLFU
	Threshold float64 `yaml:"threshold"` // 0.9 means 90%
}

type ForceGC added in v0.9.3

type ForceGC struct {
	Interval time.Duration `yaml:"interval"`
}

type Gzip added in v0.9.3

type Gzip struct {
	Enabled   bool `yaml:"enabled"`
	Threshold int  `yaml:"threshold"`
}

type Key

type Key struct {
	Query      []string `yaml:"query"` // Параметры, которые будут участвовать в ключе кэширования
	QueryBytes [][]byte
	Headers    []string `yaml:"headers"` // Хедеры, которые будут участвовать в ключе кэширования
	HeadersMap map[string]struct{}
}

type Lifetime added in v0.9.0

type Lifetime struct {
	MaxReqDuration             time.Duration `yaml:"max_req_dur"`               // If a request lifetime is longer than 100ms then request will be canceled by context.
	EscapeMaxReqDurationHeader string        `yaml:"escape_max_req_dur_header"` // If the header exists the timeout above will be skipped.
}

type Logs added in v0.9.3

type Logs struct {
	Level string `yaml:"level"` // Any zerolog.Level.
	Stats bool   `yaml:"stats"` // Should the statistic like num evictions, refreshes, rps, memory usage and so on be written in /std/out?
}

type Persistence

type Persistence struct {
	Dump Dump `yaml:"dump"`
}

type Preallocation

type Preallocation struct {
	PerShard int `yaml:"per_shard"`
}

type Refresh

type Refresh struct {
	Enabled bool `yaml:"enabled"`
	// TTL - refresh TTL (max time life of response item in cache without refreshing).
	TTL time.Duration `yaml:"ttl"` // e.g. "1d" (responses with 200 status code)
	// ErrorTTL - error refresh TTL (max time life of response item with non 200 status code in cache without refreshing).
	ErrorTTL time.Duration `yaml:"error_ttl"` // e.g. "1h" (responses with non 200 status code)
	Rate     int           `yaml:"rate"`      // Rate limiting to external backend.
	ScanRate int           `yaml:"scan_rate"` // Rate limiting of num scans items per second.
	// beta определяет коэффициент, используемый для вычисления случайного момента обновления кэша.
	// Чем выше beta, тем чаще кэш будет обновляться до истечения TTL.
	// Формула взята из подхода "stochastic cache expiration" (см. Google Staleness paper):
	// expireTime = ttl * (-beta * ln(random()))
	// Подробнее: RFC 5861 и https://web.archive.org/web/20100829170210/http://labs.google.com/papers/staleness.pdf
	// beta: "0.4"
	Beta     float64       `yaml:"beta"` // between 0 and 1
	MinStale time.Duration // computed=time.Duration(float64(TTL/ErrorTTL) * Beta)
}

type Rule

type Rule struct {
	Gzip       Gzip `yaml:"gzip"`
	PathBytes  []byte
	TTL        time.Duration `yaml:"ttl"`       // TTL for this rule.
	ErrorTTL   time.Duration `yaml:"error_ttl"` // ErrorTTL for this rule.
	Beta       float64       `yaml:"beta"`      // between 0 and 1
	CacheKey   Key           `yaml:"cache_key"`
	CacheValue Value         `yaml:"cache_value"`
	MinStale   time.Duration // computed=time.Duration(float64(TTL/ErrorTTL) * Beta)
}

type Storage

type Storage struct {
	Type string `yaml:"type"` // "malloc"
	Size uint   `yaml:"size"` // 21474836480=2gb(bytes)
}

type Upstream added in v0.9.0

type Upstream struct {
	Url     string        `yaml:"url"`     // Reverse Proxy url (can be found in Caddyfile). URL to underlying backend.
	Rate    int           `yaml:"rate"`    // Rate limiting reqs to backend per second.
	Timeout time.Duration `yaml:"timeout"` // Timeout for requests to backend.
}

type Value

type Value struct {
	Headers    []string `yaml:"headers"` // Хедеры ответа, которые будут сохранены в кэше вместе с body
	HeadersMap map[string]struct{}
}

Jump to

Keyboard shortcuts

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