Documentation
¶
Index ¶
- Variables
- func GetSingleMock(i int, path []byte, cfg config.Config) *model.Entry
- func GetSingleMockWith(i int, path []byte, cfg config.Config, brotli bool) *model.Entry
- func LoadMocks(ctx context.Context, cfg config.Config, storage Storage, num int)
- func LoadMocksWith(ctx context.Context, cfg config.Config, storage Storage, num int, brotli bool)
- func StreamEntryPointersConsecutive(ctx context.Context, cfg config.Config, path []byte, num int) <-chan *model.Entry
- func StreamEntryPointersConsecutiveWith(ctx context.Context, cfg config.Config, path []byte, num int, brotli bool) <-chan *model.Entry
- type DB
- type Dump
- type Dumper
- type InMemoryStorage
- func (s *InMemoryStorage) Clear()
- func (s *InMemoryStorage) Close() error
- func (s *InMemoryStorage) EvictN(n int) (freedBytes, items int64)
- func (s *InMemoryStorage) Get(req *model.Entry) (*model.Entry, bool)
- func (s *InMemoryStorage) Len() int64
- func (s *InMemoryStorage) Mem() int64
- func (s *InMemoryStorage) Rand() (*model.Entry, bool)
- func (s *InMemoryStorage) Refresh(entry *model.Entry) error
- func (s *InMemoryStorage) Remove(entry *model.Entry) (freedBytes int64, hit bool)
- func (s *InMemoryStorage) ScanOutdated() ([64]*model.Entry, bool)
- func (s *InMemoryStorage) Set(new *model.Entry) (persisted bool)
- func (s *InMemoryStorage) ShouldEvict() (diffBytes int64, should bool)
- func (s *InMemoryStorage) Stat() (bytes int64, length int64)
- func (s *InMemoryStorage) WalkShards(ctx context.Context, fn func(key uint64, shard *sharded.Shard[*model.Entry]))
- type Storage
Constants ¶
This section is empty.
Variables ¶
var (
ErrRefreshUpstreamBadStatusCode = errors.New("invalid upstream status code")
)
Functions ¶
func GetSingleMock ¶ added in v1.1.1
func GetSingleMockWith ¶ added in v1.4.3
GetSingleMockWith builds a single mock Entry for the given index/path/config. Brotli compression is controlled by the brotli flag.
func LoadMocksWith ¶ added in v1.4.3
LoadMocksWith generates and stores num mock entries asynchronously.
func StreamEntryPointersConsecutive ¶ added in v1.2.0
Types ¶
type DB ¶ added in v1.3.0
type DB struct {
*InMemoryStorage
// contains filtered or unexported fields
}
DB wraps the LRU storage and supervises worker groups through a Governor.
func New ¶ added in v1.4.4
New constructs the storage, wires workers and starts the governor. All transitions are done through the governor (no direct goroutine starts here).
type InMemoryStorage ¶ added in v1.4.4
type InMemoryStorage struct {
// contains filtered or unexported fields
}
InMemoryStorage — реализация поверх шардированной карты. Эвикт — random-sampling (Redis-style), без per-shard LRU.
func NewInMemory ¶ added in v1.4.4
func (*InMemoryStorage) Clear ¶ added in v1.4.4
func (s *InMemoryStorage) Clear()
func (*InMemoryStorage) Close ¶ added in v1.4.4
func (s *InMemoryStorage) Close() error
func (*InMemoryStorage) EvictN ¶ added in v1.4.4
func (s *InMemoryStorage) EvictN(n int) (freedBytes, items int64)
func (*InMemoryStorage) Get ¶ added in v1.4.4
Get — быстрый hot-path: нашли → touch (обновили TouchedAt).
func (*InMemoryStorage) Len ¶ added in v1.4.4
func (s *InMemoryStorage) Len() int64
func (*InMemoryStorage) Mem ¶ added in v1.4.4
func (s *InMemoryStorage) Mem() int64
func (*InMemoryStorage) Rand ¶ added in v1.4.4
func (s *InMemoryStorage) Rand() (*model.Entry, bool)
func (*InMemoryStorage) Refresh ¶ added in v1.4.4
func (s *InMemoryStorage) Refresh(entry *model.Entry) error
func (*InMemoryStorage) Remove ¶ added in v1.4.4
func (s *InMemoryStorage) Remove(entry *model.Entry) (freedBytes int64, hit bool)
func (*InMemoryStorage) ScanOutdated ¶ added in v1.4.4
func (s *InMemoryStorage) ScanOutdated() ([64]*model.Entry, bool)
func (*InMemoryStorage) Set ¶ added in v1.4.4
func (s *InMemoryStorage) Set(new *model.Entry) (persisted bool)
Set — вставка/обновление. Алгоритм:
- Если ключ уже есть: - payload совпал → touch и выход (persisted=true). - payload изменился → SwapPayloads + touch (persisted=true).
- Если достигнут лимит — эвикт через random-sampling под admission-фильтром: - берём дешёвого кандидата через Rand() (O(1)) для решения Allow(new, victim). - если admission запрещает — отказ (persisted=false). - иначе один раз вызываем EvictOne(). Если не удалось — отказ (persisted=false).
- Вставляем Set(key,new) (дельты считает шард), touch(new).
func (*InMemoryStorage) ShouldEvict ¶ added in v1.4.4
func (s *InMemoryStorage) ShouldEvict() (diffBytes int64, should bool)
func (*InMemoryStorage) Stat ¶ added in v1.4.4
func (s *InMemoryStorage) Stat() (bytes int64, length int64)
func (*InMemoryStorage) WalkShards ¶ added in v1.4.4
type Storage ¶
type Storage interface {
Get(*model.Entry) (entry *model.Entry, hit bool)
Set(entry *model.Entry) (persisted bool)
WalkShards(ctx context.Context, fn func(key uint64, shard *sharded.Shard[*model.Entry]))
Remove(*model.Entry) (freedBytes int64, hit bool)
Stat() (bytes int64, length int64)
EvictN(n int) (freedBytes, items int64)
ScanOutdated() ([64]*model.Entry, bool)
ShouldEvict() (diffBytes int64, should bool)
Clear()
Close() error
}
Storage is a generic interface for cache storages.