Help us shape the future of Go! Take the 2026 Go Developer Survey

cache

package
v0.3.45 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 34 Imported by: 1

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(ctx context.Context, field *ast.Field, vars map[string]any) Info

QueryInfo decides whether this field's result is cached, and under what key. Caching is asked for either by an @cache directive on the field or its definition, or — for a caller that passes a query through verbatim and so cannot add one — by a hint on the context. The directive wins where both are present, @no_cache disables either, and a mutation is never cached.

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.Catalog, error)

func (*Service) Delete

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

Delete removes the CALLER's cache entry for key. With per-identity namespacing this clears only the acting identity's copy; cross-identity invalidation (e.g. after a mutation) must use tag-based Invalidate, which is identity-independent.

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