Ristretto


dgraph-io/ristretto를 사용하는 메모리 바운드 스토리지 드라이버입니다.

참고: Go 1.19 이상 버전 필요

Table of Contents

  • Signatures

  • Installation

  • Examples

  • Config

  • Default Config

Signatures

func New(config ...Config) Storage

func (s *Storage) Get(key string) ([]byte, error)

func (s *Storage) Set(key string, val []byte, exp time.Duration) error

func (s *Storage) Delete(key string) error 

func (s *Storage) Reset() error

func (s *Storage) Close() error

func (s *Storage) Conn() *ristretto.Cache

Installation

Ristretto는 모듈을 지원하는 Go versions 최신 2개 버전에서 테스트되었습니다. 아직 모듈을 초기화하지 않았다면 먼저 초기화해야 합니다:

go mod init github.com/<user>/<repo>  

그 다음 ristretto 구현을 설치합니다:

go get github.com/gofiber/storage/ristretto/v2

Examples

스토리지 패키지를 import 합니다.

import "github.com/gofiber/storage/ristretto/v2"

다음과 같은 방법으로 스토리지를 생성할 수 있습니다:

// 기본 설정으로 초기화
store := ristretto.New()

// 사용자 정의 설정으로 초기화
store := ristretto.New(ristretto.Config{
  NumCounters: 1e7,   // 빈도를 추적할 키 수 (10M).
  MaxCost:     1<<30, // 캐시 최대 비용 (1GB).
  BufferItems: 64,    // Get 버퍼당 키 수.
})

Config

type Config struct {
  // NumCounters 빈도를 추적할 키 수 (10M).
  NumCounters int64

  // MaxCost 캐시 최대 비용 (1GB).
  MaxCost int64

  // BufferItems Get 버퍼당 키 수.
  BufferItems int64
}

Default Config

var ConfigDefault = Config{
  NumCounters: 1e7,    
  MaxCost:     1<<30,
  BufferItems: 64,
  DefaultCost: 1,    
}

Last updated