groupcache

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package groupcache provides a groupcache backed implementation of darvaza.org/cache

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogger

func NewLogger(l slog.Logger) groupcache.Logger

NewLogger creates a Logger for groupcache wrapping a given slog.Logger

func SetLogger

func SetLogger(l slog.Logger)

SetLogger sets groupcache to use a given slog.Logger

Types

type Group

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

Group implements cache.Cache around a groupcache.Group

func (*Group) Get

func (g *Group) Get(ctx context.Context, key string, sink cache.Sink) error

Get reads an entry into a Sink

func (*Group) Name

func (g *Group) Name() string

Name returns the name of the Group

func (*Group) Remove

func (g *Group) Remove(ctx context.Context, key string)

Remove removes an entry from the Group

func (*Group) Set

func (g *Group) Set(ctx context.Context, key string, value []byte,
	expire time.Time, t cache.Type) error

Set adds an entry to the Group

func (*Group) Stats

func (g *Group) Stats(t cache.Type) cache.Stats

Stats returns stats about the Group

type HTTPPool

type HTTPPool struct {
	Pool
	// contains filtered or unexported fields
}

HTTPPool implements a cache.Store using mailgun's groupcache.HTTPPool.

func NewHTTPPool

func NewHTTPPool(self string) *HTTPPool

NewHTTPPool initialises an HTTP pool of peers, and registers itself as a PeerPicker Due to groupcache's own limitations you have to choose to use either HTTPPool or NoPeersPool. There can be only one.

func NewHTTPPoolOpts

func NewHTTPPoolOpts(self string, opts *groupcache.HTTPPoolOptions) *HTTPPool

NewHTTPPoolOpts initializes an HTTP pool of peers with the given options. Unlike NewHTTPPool, this function does not register the created pool as an HTTP handler.

Due to groupcache's own limitations you have to choose to use either HTTPPool or NoPeersPool. There can be only one.

func (*HTTPPool) ServeHTTP

func (p *HTTPPool) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP handles the BasePath of the cache. "/_groupcache/" if unspecified.

type HTTPPoolOptions

type HTTPPoolOptions = groupcache.HTTPPoolOptions

HTTPPoolOptions alias for the NewHTTPPoolOpts wrapper

type Logger

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

Logger is a specific log context for groupcache

func (*Logger) Debug

func (gcl *Logger) Debug() groupcache.Logger

Debug creates a new logger context with level set to Debug

func (*Logger) Error

func (gcl *Logger) Error() groupcache.Logger

Error creates a new logger context with level set to Error

func (*Logger) ErrorField

func (gcl *Logger) ErrorField(label string, err error) groupcache.Logger

ErrorField creates a new logger context with a new field containing an error

func (*Logger) Info

func (gcl *Logger) Info() groupcache.Logger

Info creates a new logger context with level set to Info

func (*Logger) Printf

func (gcl *Logger) Printf(format string, args ...any)

Printf logs a message under a previously set level and with previously set fields

func (*Logger) StringField

func (gcl *Logger) StringField(label string, val string) groupcache.Logger

StringField creates a new logger context with a new field containing a string value

func (*Logger) Warn

func (gcl *Logger) Warn() groupcache.Logger

Warn creates a new logger context with level set to Warning

func (*Logger) WithFields

func (gcl *Logger) WithFields(fields map[string]any) groupcache.Logger

WithFields creates a new logger context with a set of new fields of arbitrary value

type Pool

type Pool struct{}

Pool implements a cache.Store using mailgun's groupcache. Groupcache is global so the Pool object doesn't contain anything

func NewNoPeersPool

func NewNoPeersPool() *Pool

NewNoPeersPool initialises groupcache with a PeerPicker that never find a peer Due to groupcache's own limitations you have to choose to use either HTTPPool or NoPeersPool. There can be only one.

func NewPool

func NewPool() *Pool

NewPool creates a Store placeholder to be used as entrypoint to a previously initialised groupcache

func (*Pool) DeregisterCache

func (*Pool) DeregisterCache(name string)

DeregisterCache removes a Group from the Pool

func (*Pool) GetCache

func (*Pool) GetCache(name string) cache.Cache

GetCache returns a named Group previously created

func (*Pool) NewCache

func (p *Pool) NewCache(name string, cacheBytes int64, getter cache.Getter) cache.Cache

NewCache creates a new Group

func (*Pool) SetLogger

func (*Pool) SetLogger(log slog.Logger)

SetLogger attaches a slog.Logger to groupcache

Jump to

Keyboard shortcuts

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