Documentation ¶
Index ¶
- Constants
- func SetSinkView(s Sink, v ByteView) error
- type ByteView
- func (v ByteView) At(i int) byte
- func (v ByteView) ByteSlice() []byte
- func (v ByteView) Copy(dest []byte) int
- func (v ByteView) Equal(b2 ByteView) bool
- func (v ByteView) EqualBytes(b2 []byte) bool
- func (v ByteView) EqualString(s string) bool
- func (v ByteView) Expire() time.Time
- func (v ByteView) Len() int
- func (v ByteView) ReadAt(p []byte, off int64) (n int, err error)
- func (v ByteView) Reader() io.ReadSeeker
- func (v ByteView) Slice(from, to int) ByteView
- func (v ByteView) SliceFrom(from int) ByteView
- func (v ByteView) String() string
- func (v ByteView) WriteTo(w io.Writer) (n int64, err error)
- type ErrNotFound
- type ErrRemoteCall
- type Group
- type GroupCacheInstance
- type HttpClient
- func (h *HttpClient) Get(ctx context.Context, in *pb.GetRequest, out *pb.GetResponse) error
- func (h *HttpClient) HashKey() string
- func (h *HttpClient) PeerInfo() peer.Info
- func (h *HttpClient) Remove(ctx context.Context, in *pb.GetRequest) error
- func (h *HttpClient) Set(ctx context.Context, in *pb.SetRequest) error
- type HttpTransport
- func (t *HttpTransport) ListenAddress() string
- func (t *HttpTransport) ListenAndServe(ctx context.Context, address string) error
- func (t *HttpTransport) New() Transport
- func (t *HttpTransport) NewClient(_ context.Context, p peer.Info) (peer.Client, error)
- func (t *HttpTransport) Register(instance GroupCacheInstance)
- func (t *HttpTransport) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (t *HttpTransport) Shutdown(ctx context.Context) error
- type HttpTransportOptions
- type Logger
- type MockClient
- func (c *MockClient) Get(ctx context.Context, in *pb.GetRequest, out *pb.GetResponse) error
- func (c *MockClient) HashKey() string
- func (c *MockClient) PeerInfo() peer.Info
- func (c *MockClient) Remove(ctx context.Context, in *pb.GetRequest) error
- func (c *MockClient) Set(ctx context.Context, in *pb.SetRequest) error
- type MockTransport
- func (t *MockTransport) ListenAddress() string
- func (t *MockTransport) ListenAndServe(_ context.Context, address string) error
- func (t *MockTransport) New() Transport
- func (t *MockTransport) NewClient(ctx context.Context, peer peer.Info) (peer.Client, error)
- func (t *MockTransport) Register(i GroupCacheInstance)
- func (t *MockTransport) Report(method string) string
- func (t *MockTransport) Reset()
- func (t *MockTransport) Shutdown(_ context.Context) error
- type Sink
- type Transport
Constants ¶
const (
DefaultBasePath = "/_groupcache/"
)
Variables ¶
This section is empty.
Functions ¶
func SetSinkView ¶
Types ¶
type ByteView ¶
type ByteView struct {
// contains filtered or unexported fields
}
A ByteView holds an immutable view of bytes. Internally it wraps either a []byte or a string, but that detail is invisible to callers.
A ByteView is meant to be used as a value type, not a pointer (like a time.Time).
func ByteViewFrom ¶
func (ByteView) EqualBytes ¶
EqualBytes returns whether the bytes in b are the same as the bytes in b2.
func (ByteView) EqualString ¶
EqualString returns whether the bytes in b are the same as the bytes in s.
func (ByteView) Reader ¶
func (v ByteView) Reader() io.ReadSeeker
Reader returns an io.ReadSeeker for the bytes in v.
type ErrNotFound ¶
type ErrNotFound struct {
Msg string
}
ErrNotFound should be returned from an implementation of `GetterFunc` to indicate the requested value is not available. When remote HTTP calls are made to retrieve values from other groupcache instances, returning this error will indicate to groupcache that the value requested is not available, and it should NOT attempt to call `GetterFunc` locally.
func (*ErrNotFound) Error ¶
func (e *ErrNotFound) Error() string
func (*ErrNotFound) Is ¶
func (e *ErrNotFound) Is(target error) bool
type ErrRemoteCall ¶
type ErrRemoteCall struct {
Msg string
}
ErrRemoteCall is returned from `group.Get()` when an error that is not a `ErrNotFound` is returned during a remote HTTP instance call
func (*ErrRemoteCall) Error ¶
func (e *ErrRemoteCall) Error() string
func (*ErrRemoteCall) Is ¶
func (e *ErrRemoteCall) Is(target error) bool
type GroupCacheInstance ¶
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
HttpClient represents an HTTP client used to make requests to a specific peer.
func (*HttpClient) Get ¶
func (h *HttpClient) Get(ctx context.Context, in *pb.GetRequest, out *pb.GetResponse) error
func (*HttpClient) HashKey ¶
func (h *HttpClient) HashKey() string
func (*HttpClient) PeerInfo ¶
func (h *HttpClient) PeerInfo() peer.Info
func (*HttpClient) Remove ¶
func (h *HttpClient) Remove(ctx context.Context, in *pb.GetRequest) error
func (*HttpClient) Set ¶
func (h *HttpClient) Set(ctx context.Context, in *pb.SetRequest) error
type HttpTransport ¶
type HttpTransport struct {
// contains filtered or unexported fields
}
HttpTransport defines the HTTP transport
func NewHttpTransport ¶
func NewHttpTransport(opts HttpTransportOptions) *HttpTransport
NewHttpTransport returns a new HttpTransport instance based on the provided HttpTransportOptions. Example usage:
transport := groupcache.NewHttpTransport(groupcache.HttpTransportOptions{ BasePath: "/_groupcache/", Scheme: "http", Client: nil, }) instance := groupcache.New(.....) // Must register the groupcache instance before using transport transport.Register(instance)
func (*HttpTransport) ListenAddress ¶
func (t *HttpTransport) ListenAddress() string
ListenAddress returns the address the server is listening on after calling ListenAndServe().
func (*HttpTransport) ListenAndServe ¶
func (t *HttpTransport) ListenAndServe(ctx context.Context, address string) error
ListenAndServe starts a new http server listening on the provided address:port
func (*HttpTransport) New ¶
func (t *HttpTransport) New() Transport
New creates a new unregistered HttpTransport, using the same options as its parent.
func (*HttpTransport) Register ¶
func (t *HttpTransport) Register(instance GroupCacheInstance)
Register registers the provided instance with this transport.
func (*HttpTransport) ServeHTTP ¶
func (t *HttpTransport) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles all incoming HTTP requests received by the server spawned by ListenAndServe()
type HttpTransportOptions ¶
type HttpTransportOptions struct { // Context (Optional) specifies a context for the server to use when it // receives a request. // defaults to http.Request.Context() Context func(*http.Request) context.Context // Client (Optional) provide a custom http client with TLS config. // defaults to http.DefaultClient Client *http.Client // Scheme (Optional) is either `http` or `https`. `Scheme` is reserved here for future use. // defaults to `http` when TLSConfig is not set. Scheme string // BasePath (Optional) specifies the HTTP path that will serve groupcache requests. // defaults to "/_groupcache/". BasePath string // Logger Logger Logger // TLS support. TLSConfig *tls.Config }
HttpTransportOptions options for creating a new HttpTransport
type MockClient ¶
type MockClient struct {
// contains filtered or unexported fields
}
func (*MockClient) Get ¶
func (c *MockClient) Get(ctx context.Context, in *pb.GetRequest, out *pb.GetResponse) error
func (*MockClient) HashKey ¶
func (c *MockClient) HashKey() string
func (*MockClient) PeerInfo ¶
func (c *MockClient) PeerInfo() peer.Info
func (*MockClient) Remove ¶
func (c *MockClient) Remove(ctx context.Context, in *pb.GetRequest) error
func (*MockClient) Set ¶
func (c *MockClient) Set(ctx context.Context, in *pb.SetRequest) error
type MockTransport ¶
type MockTransport struct {
// contains filtered or unexported fields
}
MockTransport is intended to be used as a singleton. Pass a new instance of this singleton into groupcache.New() by calling MockTransport.New(). You can then inspect the parent MockTransport for call statistics of the children in tests. This Transport is NOT THREAD SAFE Example usage:
t := NewMockTransport() i := groupcache.New(groupcache.Options{Transport: t.New()})
func NewMockTransport ¶
func NewMockTransport() *MockTransport
func (*MockTransport) ListenAddress ¶
func (t *MockTransport) ListenAddress() string
func (*MockTransport) ListenAndServe ¶
func (t *MockTransport) ListenAndServe(_ context.Context, address string) error
func (*MockTransport) New ¶
func (t *MockTransport) New() Transport
func (*MockTransport) Register ¶
func (t *MockTransport) Register(i GroupCacheInstance)
func (*MockTransport) Report ¶
func (t *MockTransport) Report(method string) string
func (*MockTransport) Reset ¶
func (t *MockTransport) Reset()
type Sink ¶
type Sink interface { // SetString sets the value to s. SetString(s string, e time.Time) error // SetBytes sets the value to the contents of v. // The caller retains ownership of v. SetBytes(v []byte, e time.Time) error // SetProto sets the value to the encoded version of m. // The caller retains ownership of m. SetProto(m proto.Message, e time.Time) error // View returns a frozen view of the bytes for caching. View() (ByteView, error) }
A Sink receives data from a Get call.
Implementation of Getter must call exactly one of the Set methods on success.
`e` sets an optional time in the future when the value will expire. If you don't want expiration, pass the zero value for `time.Time` (for instance, `time.Time{}`).
func AllocatingByteSliceSink ¶
AllocatingByteSliceSink returns a Sink that allocates a byte slice to hold the received value and assigns it to *dst. The memory is not retained by groupcache.
func ByteViewSink ¶
ByteViewSink returns a Sink that populates a ByteView.
func StringSink ¶
StringSink returns a Sink that populates the provided string pointer.
func TruncatingByteSliceSink ¶
TruncatingByteSliceSink returns a Sink that writes up to len(*dst) bytes to *dst. If more bytes are available, they're silently truncated. If fewer bytes are available than len(*dst), *dst is shrunk to fit the number of bytes available.
type Transport ¶
type Transport interface { // New returns a clone of this instance suitable for passing to groupcache.New() // Example usage: // // transport := groupcache.NewHttpTransport(groupcache.HttpTransportOptions{}) // groupcache.New(groupcache.Config{Transport: transport.New()}) New() Transport // Register registers the provided *Instance with the HttpTransport. // // This method sets the instance field of the HttpTransport to the provided instance. // The instance is used by the ServeHTTP method to serve groupcache requests. Register(instance GroupCacheInstance) // NewClient returns a new Client suitable for the transport implementation. The client returned is used to communicate // with a specific peer. This method will be called for each peer in the peer list when groupcache.Instance.SetPeers() is // called. NewClient(ctx context.Context, peer peer.Info) (peer.Client, error) // ListenAndServe spawns a server that will handle incoming requests for this transport // This is used by daemon and cluster packages to create a cluster of instances using // this specific transport. ListenAndServe(ctx context.Context, address string) error // Shutdown shuts down the server started when calling ListenAndServe() Shutdown(ctx context.Context) error // ListenAddress returns the address the server is listening on after calling ListenAndServe(). ListenAddress() string }