cache

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2025 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ItemDataTypeMap = iota
	ItemDataTypeArrowTable
	ItemDataTypeJsonValue
	ItemDataTypeBytes
	ItemDataTypeString
	ItemDataTypeResponse
	ItemNil
)

Variables

View Source
var ErrMissCache = errors.New("Key not found in cache")
View Source
var (
	ErrNoCacheConfigured = errors.New("no cache configured")
)

Functions

func FieldKey

func FieldKey(field *ast.Field, vars map[string]any) (string, error)

func QueryKey

func QueryKey(query string, vars map[string]any) (string, error)

Types

type BackendType

type BackendType string
const (
	L2RedisBackend     BackendType = "redis"
	L2MemcachedBackend BackendType = "memcached"
)

type CacheItem

type CacheItem struct {
	Type int8
	Data any
}

func NewCacheItem

func NewCacheItem(data any) (*CacheItem, error)

func (*CacheItem) DecodeMsgpack

func (item *CacheItem) DecodeMsgpack(dec *msgpack.Decoder) (err error)

func (*CacheItem) EncodeMsgpack

func (item *CacheItem) EncodeMsgpack(enc *msgpack.Encoder) error

type Config

type Config struct {
	TTL types.Interval `json:"ttl"` // default time to live for the cache
	L1  L1Config       `json:"l1"`  // L1 cache configuration
	L2  L2Config       `json:"l2"`  // L2 cache configuration
}

func (Config) Init

type Info

type Info struct {
	Use        bool
	Key        string
	Tags       []string
	TTL        time.Duration
	Invalidate bool
}

func QueryInfo

func QueryInfo(field *ast.Field, vars map[string]any) Info

func (*Info) Merge

func (i *Info) Merge(other Info)

func (Info) Options

func (i Info) Options() []Option

type L1Config

type L1Config struct {
	Enabled      bool           `json:"enabled"`
	MaxSize      int            `json:"max_size"`      // Maximum size of the cache Megabytes
	MaxItemSize  int            `json:"max_item_size"` // Maximum size of an item in the cache
	Shards       int            `json:"shards"`        // Number of shards in the cache
	CleanTime    types.Interval `json:"clean_time"`    // Time to clean the cache
	EvictionTime types.Interval `json:"eviction_time"` // Time to evict items from the cache
}

func (L1Config) Init

type L2Config

type L2Config struct {
	Enabled bool        `json:"enabled"`
	Backend BackendType `json:"backend"` // Backend type for the L2 cache

	Addresses []string `json:"addresses"` // Addresses for the L2 cache
	Database  int      `json:"database"`  // Database for the L2 cache (for Redis)
	Username  string   `json:"username"`  // Username for the L2 cache (for Redis)
	Password  string   `json:"password"`  // Password for the L2 cache (for Redis)
}

func (L2Config) Init

type Option

type Option func(o *Options)

func WithTTL

func WithTTL(ttl time.Duration) Option

func WithTags

func WithTags(tags ...string) Option

type Options

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

func ApplyOptions

func ApplyOptions(opts ...Option) *Options

type Service

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

func New

func New(config Config) *Service

func (*Service) AsModule added in v0.1.9

func (s *Service) AsModule() bool

func (*Service) Attach

func (s *Service) Attach(ctx context.Context, pool *db.Pool) error

func (*Service) Catalog

func (s *Service) Catalog(ctx context.Context) cs.Source

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, key string) error

func (*Service) Engine

func (s *Service) Engine() engines.Engine

func (*Service) Get

func (s *Service) Get(ctx context.Context, key string) (any, error)

func (*Service) Init

func (s *Service) Init(ctx context.Context) error

func (*Service) Invalidate

func (s *Service) Invalidate(ctx context.Context, tags ...string) error

func (*Service) IsReadonly

func (s *Service) IsReadonly() bool

func (*Service) Load

func (s *Service) Load(ctx context.Context, key string, fn func() (any, error), options ...Option) (any, error)

func (*Service) Name

func (s *Service) Name() string

func (*Service) Set

func (s *Service) Set(ctx context.Context, key string, data any, options ...Option) error

Jump to

Keyboard shortcuts

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