autocache

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package autocache implements a key value store (kv.Store) using autocache which combines functionality from groupcache, and memberlist libraries. For more details, see https://github.com/pomerium/autocache

Index

Constants

View Source
const Name = "autocache"

Name represents autocache's shorthand named.

Variables

View Source
var DefaultOptions = &Options{
	Addr:      ":8333",
	Port:      8333,
	Scheme:    "http",
	CacheSize: 10 << 20,
	Group:     "default",
	GetterFn: func(ctx context.Context, id string, dest groupcache.Sink) error {
		b := fromContext(ctx)
		if len(b) == 0 {
			return fmt.Errorf("autocache: empty ctx for id: %s", id)
		}
		if err := dest.SetBytes(b); err != nil {
			return fmt.Errorf("autocache: sink error %w", err)
		}
		return nil
	},
}

DefaultOptions are the default options used by the autocache service.

Functions

func QueryParamToCtx

func QueryParamToCtx(next http.Handler) http.Handler

QueryParamToCtx takes a value from a query param and adds it to the current request request context.

Types

type Options

type Options struct {
	Addr          string
	CacheSize     int64
	ClusterDomain string
	GetterFn      groupcache.GetterFunc
	Group         string
	Log           *stdlog.Logger
	Port          int
	Scheme        string
	SharedKey     string
}

Options represent autocache options.

type Store

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

Store implements a the store interface for autocache, a distributed cache with gossip based peer membership enrollment. https://github.com/pomerium/autocache

func New

func New(o *Options) (*Store, error)

New creates a new autocache key value store. Autocache will start several services to support distributed cluster management and membership. A HTTP server will be used by groupcache to perform cross node-RPC. By default that server will start on port “:8333`. Memberlist will likewise start and listen for group membership on port

NOTE: RPC communication between nodes is _authenticated_ but not encrypted. NOTE: Groupchache starts a HTTP listener (Default: :8333) NOTE: Memberlist starts a GOSSIP listener on TCP/UDP. (Default: :7946)

func (Store) Close

func (s Store) Close(ctx context.Context) error

Close shuts down any HTTP server used for groupcache pool, and also stop any background maintenance of memberlist.

func (*Store) Get

func (s *Store) Get(ctx context.Context, k string) (bool, []byte, error)

Get retrieves the value for a key in the bucket.

func (Store) Set

func (s Store) Set(ctx context.Context, k string, v []byte) error

Set stores a key value pair. Since group cache actually only implements Get, we have to be a little creative in how we smuggle in value using context.

Jump to

Keyboard shortcuts

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