### Register Server Start Hook Source: https://pkg.go.dev/github.com/golang/groupcache/index Registers a hook that is executed when the first group is created. This is useful for performing setup tasks that depend on the availability of a group instance. ```go func RegisterServerStart(fn func()) ``` -------------------------------- ### ProtoGetter Interface (Go) Source: https://pkg.go.dev/github.com/golang/groupcache/index Defines the ProtoGetter interface, which must be implemented by a peer. It includes the Get method for retrieving data associated with a key. ```Go type ProtoGetter interface { Get(ctx context.Context, in *pb.GetRequest, out *pb.GetResponse) error } ``` -------------------------------- ### ProtoGetter Interface Source: https://pkg.go.dev/github.com/golang/groupcache/index Defines the ProtoGetter interface, which must be implemented by a peer to handle Get requests. ```APIDOC ## Interface: ProtoGetter ### Description Interface that must be implemented by a peer. ### Method - **Get(ctx context.Context, in *pb.GetRequest, out *pb.GetResponse) error**: Retrieves data for a given request. Implementation must call one of the Set methods on success. ``` -------------------------------- ### Group Get Method Source: https://pkg.go.dev/github.com/golang/groupcache/index Retrieves data from the group for a given key. ```go func (g *Group) Get(ctx context.Context, key string, dest Sink) error ``` -------------------------------- ### GetterFunc Get Method Source: https://pkg.go.dev/github.com/golang/groupcache/index Implements the Get method for a GetterFunc, allowing it to be used as a Getter. It takes a context, key, and a Sink to retrieve the data. ```go func (f GetterFunc) Get(ctx context.Context, key string, dest Sink) error ``` -------------------------------- ### Getter Interface Source: https://pkg.go.dev/github.com/golang/groupcache/index Defines the Get method for loading data identified by a key. ```go type Getter interface { // Get returns the value identified by key, populating dest. // // The returned data must be unversioned. That is, key must // uniquely describe the loaded data, without an implicit // current time, and without relying on cache expiration // mechanisms. Get(ctx context.Context, key string, dest Sink) error } ``` -------------------------------- ### Register New Group Hook Source: https://pkg.go.dev/github.com/golang/groupcache/index Registers a hook that is executed every time a new group is created. This allows for custom initialization or setup logic when a group is instantiated. ```go func RegisterNewGroupHook(fn func(*Group)) ``` -------------------------------- ### Implement GetGets Method in Go Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/testpb Provides a getter method for the 'Gets' field within the StatsResponse structure. This method returns the total number of gets as an int64. ```go func (m *StatsResponse) GetGets() int64 ``` -------------------------------- ### NewGroup Function Source: https://pkg.go.dev/github.com/golang/groupcache/index Creates a group-aware Getter, ensuring only one Get call per key across peers. ```go func NewGroup(name string, cacheBytes int64, getter Getter) *Group ``` -------------------------------- ### Define StatsResponse Structure in Go Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/testpb Defines the StatsResponse structure, which holds various statistics related to cache performance, including gets, cache hits, fills, total allocations, and peer/local load statistics. It's designed to capture detailed operational metrics. ```go type StatsResponse struct { Gets *int64 `protobuf:"varint,1,opt,name=gets" json:"gets,omitempty" CacheHits *int64 `protobuf:"varint,12,opt,name=cache_hits" json:"cache_hits,omitempty" Fills *int64 `protobuf:"varint,2,opt,name=fills" json:"fills,omitempty" TotalAlloc *uint64 `protobuf:"varint,3,opt,name=total_alloc" json:"total_alloc,omitempty" MainCache *CacheStats `protobuf:"bytes,4,opt,name=main_cache" json:"main_cache,omitempty" HotCache *CacheStats `protobuf:"bytes,5,opt,name=hot_cache" json:"hot_cache,omitempty" ServerIn *int64 `protobuf:"varint,6,opt,name=server_in" json:"server_in,omitempty" Loads *int64 `protobuf:"varint,8,opt,name=loads" json:"loads,omitempty" PeerLoads *int64 `protobuf:"varint,9,opt,name=peer_loads" json:"peer_loads,omitempty" PeerErrors *int64 `protobuf:"varint,10,opt,name=peer_errors" json:"peer_errors,omitempty" LocalLoads *int64 `protobuf:"varint,11,opt,name=local_loads" json:"local_loads,omitempty" XXX_unrecognized []byte `json:"-" } ``` -------------------------------- ### CacheStats Structure Source: https://pkg.go.dev/github.com/golang/groupcache/index Defines statistics for a cache, including bytes, items, gets, hits, and evictions. ```go type CacheStats struct { Bytes int64 Items int64 Gets int64 Hits int64 Evictions int64 } ``` -------------------------------- ### CacheStats Type Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/testpb Represents statistics for a cache, including items, bytes, gets, hits, and evicts. ```APIDOC ## Type CacheStats ### Description Represents statistics for a cache, including the number of items, bytes used, total gets, cache hits, and evictions. ### Fields - **items** (int64) - Optional - The number of items currently in the cache. - **bytes** (int64) - Optional - The total number of bytes occupied by items in the cache. - **gets** (int64) - Optional - The total number of times items were requested from the cache. - **hits** (int64) - Optional - The number of times a requested item was found in the cache. - **evicts** (int64) - Optional - The number of times items were evicted from the cache to make space. ### Methods - `GetBytes() int64`: Returns the number of bytes in the cache. - `GetEvicts() int64`: Returns the number of evictions from the cache. - `GetGets() int64`: Returns the total number of gets from the cache. - `GetHits() int64`: Returns the number of cache hits. - `GetItems() int64`: Returns the number of items in the cache. - `ProtoMessage()`: Marks the struct as a protobuf message. - `Reset()`: Resets the cache statistics. - `String() string`: Returns a string representation of the cache statistics. ``` -------------------------------- ### ByteView Methods Source: https://pkg.go.dev/github.com/golang/groupcache/index Provides methods for accessing and comparing immutable byte slices held by a ByteView. These include getting a byte at an index, retrieving a copy of the data, comparing with other ByteViews or byte slices, and slicing operations. ```go func (v ByteView) At(i int) byte ``` ```go func (v ByteView) ByteSlice() []byte ``` ```go func (v ByteView) Copy(dest []byte) int ``` ```go func (v ByteView) Equal(b2 ByteView) bool ``` ```go func (v ByteView) EqualBytes(b2 []byte) bool ``` ```go func (v ByteView) EqualString(s string) bool ``` ```go func (v ByteView) Len() int ``` ```go func (v ByteView) ReadAt(p []byte, off int64) (n int, err error) ``` ```go func (v ByteView) Reader() io.ReadSeeker ``` ```go func (v ByteView) Slice(from, to int) ByteView ``` ```go func (v ByteView) SliceFrom(from int) ByteView ``` ```go func (v ByteView) String() string ``` ```go func (v ByteView) WriteTo(w io.Writer) (n int64, err error) ``` -------------------------------- ### Sink Interface for Data Reception (Go) Source: https://pkg.go.dev/github.com/golang/groupcache/index Defines the Sink interface, used to receive data from a Get call. Implementations must call one of the Set methods (SetString, SetBytes, SetProto) on success. ```Go type Sink interface { // SetString sets the value to s. SetString(s string) error // SetBytes sets the value to the contents of v. // The caller retains ownership of v. SetBytes(v []byte) error // SetProto sets the value to the encoded version of m. // The caller retains ownership of m. SetProto(m proto.Message) error // contains filtered or unexported methods } ``` -------------------------------- ### lru: Get an item from the cache Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/lru Retrieves the value associated with a given key from the cache. It returns the value and a boolean indicating if the key was found. ```go func (c *Cache) Get(key Key) (value interface{}, ok bool) ``` -------------------------------- ### Stats Structure for Group Statistics (Go) Source: https://pkg.go.dev/github.com/golang/groupcache/index Defines the Stats structure, which holds per-group statistics. It tracks various metrics like GET requests, cache hits, peer loads, errors, and local load attempts. ```Go type Stats struct { Gets AtomicInt // any Get request, including from peers CacheHits AtomicInt // either cache was good PeerLoads AtomicInt // either remote load or remote cache hit (not an error) PeerErrors AtomicInt Loads AtomicInt // (gets - cacheHits) LoadsDeduped AtomicInt // after singleflight LocalLoads AtomicInt // total good local loads LocalLoadErrs AtomicInt // total bad local loads ServerRequests AtomicInt // gets that came over the network from peers } ``` -------------------------------- ### CacheStats Struct Definition (Go) Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/testpb Defines the CacheStats message structure, used to hold statistics related to a cache. It includes fields for items, bytes, gets, hits, and evicts, all as pointers to int64. This structure is part of the generated protocol buffer code. ```Go type CacheStats struct { Items *int64 `protobuf:"varint,1,opt,name=items" json:"items,omitempty"` Bytes *int64 `protobuf:"varint,2,opt,name=bytes" json:"bytes,omitempty"` Gets *int64 `protobuf:"varint,3,opt,name=gets" json:"gets,omitempty"` Hits *int64 `protobuf:"varint,4,opt,name=hits" json:"hits,omitempty"` Evicts *int64 `protobuf:"varint,5,opt,name=evicts" json:"evicts,omitempty"` XXX_unrecognized []byte `json:"-"` } ``` -------------------------------- ### NewHTTPPoolOpts Function Source: https://pkg.go.dev/github.com/golang/groupcache/index Initializes an HTTP pool with options, requiring manual registration as an HTTP handler. ```go func NewHTTPPoolOpts(self string, o *HTTPPoolOptions) *HTTPPool ``` -------------------------------- ### RegisterServerStart Source: https://pkg.go.dev/github.com/golang/groupcache/index Registers a hook that executes when the first cache group is created. This can be used to trigger server startup or related initialization tasks. ```APIDOC ## RegisterServerStart ### Description Registers a hook that is run when the first group is created. ### Method FUNC ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response None #### Success Response (200) None #### Response Example None ``` -------------------------------- ### CacheStats GetGets Method (Go) Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/testpb A getter method for the Gets field of the CacheStats struct. It returns the total number of gets from the cache as an int64. ```Go func (m *CacheStats) GetGets() int64 ``` -------------------------------- ### HTTPPool Creation Source: https://pkg.go.dev/github.com/golang/groupcache/index Provides constructors for creating HTTPPool instances, which manage peer discovery and HTTP serving for the cache. It allows specifying the self identifier and optional options. ```go func NewHTTPPool(self string) *HTTPPool ``` ```go func NewHTTPPoolOpts(self string, o *HTTPPoolOptions) *HTTPPool ``` -------------------------------- ### HTTPPool Configuration Source: https://pkg.go.dev/github.com/golang/groupcache/index Defines the configuration options available for setting up an HTTPPool, including base path, replica count, and hash function. ```APIDOC ## GET /websites/pkg_go_dev_github_com_golang_groupcache/options ### Description Describes the configuration options for an HTTPPool. ### Method GET ### Endpoint /websites/pkg_go_dev_github_com_golang_groupcache/options ### Parameters #### Request Body - **BasePath** (string) - Optional - Specifies the HTTP path that will serve groupcache requests. Defaults to "/_groupcache/". - **Replicas** (int) - Optional - Specifies the number of key replicas on the consistent hash. Defaults to 50. - **HashFn** (consistenthash.Hash) - Optional - Specifies the hash function of the consistent hash. Defaults to crc32.ChecksumIEEE. ``` -------------------------------- ### HTTPPool Peer Management and Serving Source: https://pkg.go.dev/github.com/golang/groupcache/index Defines methods for HTTPPool to pick peers based on a key, serve HTTP requests, and set the available peers. ```go func (p *HTTPPool) PickPeer(key string) (ProtoGetter, bool) ``` ```go func (p *HTTPPool) ServeHTTP(w http.ResponseWriter, r *http.Request) ``` ```go func (p *HTTPPool) Set(peers ...string) ``` -------------------------------- ### RegisterPeerPicker Source: https://pkg.go.dev/github.com/golang/groupcache/index Registers a function to initialize peer discovery. This function is called once when the first group is created. It should be used exclusively, either this or RegisterPerGroupPeerPicker. ```APIDOC ## RegisterPeerPicker ### Description Registers the peer initialization function. It is called once, when the first group is created. Either RegisterPeerPicker or RegisterPerGroupPeerPicker should be called exactly once, but not both. ### Method FUNC ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response None #### Success Response (200) None #### Response Example None ``` -------------------------------- ### HTTP Pool Methods (Go) Source: https://pkg.go.dev/github.com/golang/groupcache/index Provides essential methods for the HTTPPool type, including picking peers, serving HTTP requests, and setting the pool's peers. The Set method updates the list of available peers. ```Go func (p *HTTPPool) PickPeer(key string) (ProtoGetter, bool) func (p *HTTPPool) ServeHTTP(w http.ResponseWriter, r *http.Request) func (p *HTTPPool) Set(peers ...string) ``` -------------------------------- ### Sink Interface and Implementations Source: https://pkg.go.dev/github.com/golang/groupcache/index Details the Sink interface for receiving data and provides documentation for its various implementations. ```APIDOC ## Interface: Sink ### Description Interface for receiving data from a Get call. Implementations must call exactly one of the Set methods on success. ### Methods - **SetString(s string) error**: Sets the value to the given string. - **SetBytes(v []byte) error**: Sets the value to the contents of the byte slice. - **SetProto(m proto.Message) error**: Sets the value to the encoded version of the proto message. ## Sink Implementations - **AllocatingByteSliceSink(dst *[]byte) Sink**: Returns a Sink that allocates a byte slice to hold the received value and assigns it to *dst. - **ByteViewSink(dst *ByteView) Sink**: Returns a Sink that populates a ByteView. - **ProtoSink(m proto.Message) Sink**: Returns a sink that unmarshals binary proto values into m. - **StringSink(sp *string) Sink**: Returns a Sink that populates the provided string pointer. - **TruncatingByteSliceSink(dst *[]byte) Sink**: Returns a Sink that writes up to len(*dst) bytes to *dst, truncating if necessary. It also shrinks *dst if fewer bytes are available. ``` -------------------------------- ### NewHTTPPool Function Source: https://pkg.go.dev/github.com/golang/groupcache/index Initializes an HTTP pool and registers it as a PeerPicker and HTTP handler. ```go func NewHTTPPool(self string) *HTTPPool ``` -------------------------------- ### HTTP Pool Options Configuration (Go) Source: https://pkg.go.dev/github.com/golang/groupcache/index Defines the configuration options for HTTPPool, allowing customization of the base path for groupcache requests, the number of key replicas for consistent hashing, and the hash function to be used. ```Go type HTTPPoolOptions struct { // BasePath specifies the HTTP path that will serve groupcache requests. // If blank, it defaults to "/_groupcache/". BasePath string // Replicas specifies the number of key replicas on the consistent hash. // If blank, it defaults to 50. Replicas int // HashFn specifies the hash function of the consistent hash. // If blank, it defaults to crc32.ChecksumIEEE. HashFn consistenthash.Hash } ``` -------------------------------- ### lru: Get the number of items in the cache Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/lru Returns the current number of items stored in the LRU cache. ```go func (c *Cache) Len() int ``` -------------------------------- ### New Map Constructor in Go Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/consistenthash Creates a new Map instance for the ring hash. It requires the number of replicas for each key and a custom hash function. ```Go func New(replicas int, fn Hash) *Map ``` -------------------------------- ### TestResponse Type Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/testpb A sample response message type for testing. ```APIDOC ## Type TestResponse ### Description This message type represents a sample response for testing purposes, containing a single string field 'value'. ### Fields - **value** (string) - The string value returned in the response. ### Methods - `GetValue() string`: Retrieves the value of the 'value' field. - `ProtoMessage()`: Marks the struct as a protobuf message. - `Reset()`: Resets the value field of the response. - `String() string`: Returns a string representation of the response message. ``` -------------------------------- ### Group Operations API Source: https://pkg.go.dev/github.com/golang/groupcache/index Enables operations on an existing cache group, including retrieving statistics, getting data, and accessing the group's name. ```APIDOC ## CacheStats ### Description Retrieves statistics about a specific cache within the group. ### Method GET ### Endpoint /group/{name}/stats/{cacheType} ### Parameters #### Path Parameters - **name** (string) - Required - The name of the group. - **cacheType** (CacheType) - Required - The type of cache to get statistics for (MainCache or HotCache). ### Response #### Success Response (200) - **CacheStats** (object) - An object containing cache statistics (Bytes, Items, Gets, Hits, Evictions). #### Response Example ```json { "Bytes": 10240, "Items": 100, "Gets": 1000, "Hits": 500, "Evictions": 10 } ``` ## Get ### Description Retrieves data for a given key from the group. The `dest` Sink is populated with the retrieved value. ### Method GET ### Endpoint /group/{name}/get ### Parameters #### Path Parameters - **name** (string) - Required - The name of the group. #### Query Parameters - **key** (string) - Required - The key of the data to retrieve. #### Request Body - **dest** (Sink) - Required - The Sink interface to populate with the retrieved data. ### Response #### Success Response (200) - **error** (error) - nil if successful. #### Response Example ```json { "error": null } ``` ## Name ### Description Returns the name of the group. ### Method GET ### Endpoint /group/{name}/name ### Parameters #### Path Parameters - **name** (string) - Required - The name of the group. ### Response #### Success Response (200) - **string** - The name of the group. #### Response Example ```json { "name": "my-group" } ``` ``` -------------------------------- ### AtomicInt Operations Source: https://pkg.go.dev/github.com/golang/groupcache/index Defines methods for atomically adding to and getting the value of an AtomicInt, which is an int64 type. It also includes a String method for string representation. ```go func (i *AtomicInt) Add(n int64) ``` ```go func (i *AtomicInt) Get() int64 ``` ```go func (i *AtomicInt) String() string ``` -------------------------------- ### ByteView ReadAt Implementation Source: https://pkg.go.dev/github.com/golang/groupcache/index Implements io.ReaderAt for the bytes in a ByteView. ```go func (v ByteView) ReadAt(p []byte, off int64) (n int, err error) ``` -------------------------------- ### HTTPPool Source: https://pkg.go.dev/github.com/golang/groupcache/index Manages HTTP-based peer discovery and serves cache data over HTTP. Includes options for configuring the pool and handling incoming requests. ```APIDOC ## HTTPPool ### Description Manages HTTP-based peer discovery and serving cache data over HTTP. ### Constructors #### NewHTTPPool Creates a new HTTPPool with the given self identifier. ```go func NewHTTPPool(self string) *HTTPPool ``` #### NewHTTPPoolOpts Creates a new HTTPPool with the given self identifier and options. ```go func NewHTTPPoolOpts(self string, o *HTTPPoolOptions) *HTTPPool ``` ### Methods #### PickPeer Selects a peer responsible for the given key. ```go func (p *HTTPPool) PickPeer(key string) (ProtoGetter, bool) ``` #### ServeHTTP Handles incoming HTTP requests for serving cache data. ```go func (p *HTTPPool) ServeHTTP(w http.ResponseWriter, r *http.Request) ``` #### Set Sets the peers that this HTTP pool can connect to. ```go func (p *HTTPPool) Set(peers ...string) ``` ``` -------------------------------- ### HTTPPool Structure Source: https://pkg.go.dev/github.com/golang/groupcache/index Implements PeerPicker for a pool of HTTP peers, with options for context and transport. ```go type HTTPPool struct { // Context optionally specifies a context for the server to use when it // receives a request. // If nil, the server uses the request's context Context func(*http.Request) context.Context // Transport optionally specifies an http.RoundTripper for the client // to use when it makes a request. // If nil, the client uses http.DefaultTransport. Transport func(context.Context) http.RoundTripper // contains filtered or unexported fields } ``` -------------------------------- ### Get Key from Ring Hash in Go Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/consistenthash Retrieves the closest key in the hash map to the provided input key. This is used to find the node responsible for a given key. ```Go func (m *Map) Get(key string) string ``` -------------------------------- ### Register Peer Picker Source: https://pkg.go.dev/github.com/golang/groupcache/index Registers a peer initialization function that is called once when the first group is created. This function is responsible for providing a PeerPicker implementation. It should be called exactly once, along with either RegisterPeerPicker or RegisterPerGroupPeerPicker, but not both. ```go func RegisterPeerPicker(fn func() PeerPicker) ``` -------------------------------- ### String method for GetResponse - groupcachepb Go Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/groupcachepb Provides a string representation of the GetResponse message. Useful for debugging. ```go func (m *GetResponse) String() string ``` -------------------------------- ### ByteView String Conversion Source: https://pkg.go.dev/github.com/golang/groupcache/index Returns the data in a ByteView as a string, potentially making a copy. ```go func (v ByteView) String() string ``` -------------------------------- ### Implement String Method for TestResponse in Go Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/testpb Returns a string representation of the TestResponse message, useful for debugging and logging. ```go func (m *TestResponse) String() string ``` -------------------------------- ### HTTPPool Request Handling Source: https://pkg.go.dev/github.com/golang/groupcache/index Details the method for serving HTTP requests, which is the primary way the HTTP pool interacts over the network. ```APIDOC ## POST /websites/pkg_go_dev_github_com_golang_groupcache ### Description Handles incoming HTTP requests for the groupcache service. ### Method POST ### Endpoint /_groupcache/ ### Functions - **ServeHTTP(w http.ResponseWriter, r *http.Request)**: Serves HTTP requests for the groupcache pool. ``` -------------------------------- ### HTTP Pool API Source: https://pkg.go.dev/github.com/golang/groupcache/index Provides functionality for creating and configuring HTTP pools for peer discovery and communication. ```APIDOC ## NewHTTPPool ### Description Initializes an HTTP pool of peers and registers itself as a PeerPicker and an http.Handler. ### Method POST ### Endpoint /httppool ### Parameters #### Request Body - **self** (string) - Required - The base URL of the current server (e.g., "http://example.net:8000"). ### Response #### Success Response (200) - ***HTTPPool** (object) - A pointer to the initialized HTTPPool object. #### Response Example ```json { "HTTPPool": "0xc00012b000" } ``` ## NewHTTPPoolOpts ### Description Initializes an HTTP pool of peers with custom options. This function does not automatically register the pool as an HTTP handler; it must be done manually. ### Method POST ### Endpoint /httppool/opts ### Parameters #### Request Body - **self** (string) - Required - The base URL of the current server. - **o** (HTTPPoolOptions) - Optional - An object containing HTTPPool options. ### Request Example ```json { "self": "http://example.net:8000", "o": { "Context": "request.Context", "Transport": "http.DefaultTransport" } } ``` ### Response #### Success Response (200) - ***HTTPPool** (object) - A pointer to the initialized HTTPPool object. #### Response Example ```json { "HTTPPool": "0xc00012b0f0" } ``` ``` -------------------------------- ### Group Creation and Retrieval Source: https://pkg.go.dev/github.com/golang/groupcache/index Provides functions for creating new cache groups with specified byte limits and getters, and for retrieving existing groups by name. ```go func GetGroup(name string) *Group ``` ```go func NewGroup(name string, cacheBytes int64, getter Getter) *Group ``` -------------------------------- ### ByteView WriteTo Implementation Source: https://pkg.go.dev/github.com/golang/groupcache/index Implements io.WriterTo for the bytes in a ByteView. ```go func (v ByteView) WriteTo(w io.Writer) (n int64, err error) ``` -------------------------------- ### Register Per-Group Peer Picker Source: https://pkg.go.dev/github.com/golang/groupcache/index Registers a peer initialization function that takes the group name as an argument, used for selecting a PeerPicker. This function is called once when the first group is created. It should be called exactly once, along with either RegisterPeerPicker or RegisterPerGroupPeerPicker, but not both. ```go func RegisterPerGroupPeerPicker(fn func(groupName string) PeerPicker) ``` -------------------------------- ### Implement String Method in Go Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/testpb Returns a string representation of the StatsResponse message, useful for debugging and logging. ```go func (m *StatsResponse) String() string ``` -------------------------------- ### GetMinuteQps method for GetResponse - groupcachepb Go Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/groupcachepb A method for the GetResponse struct that returns the queries per minute. This is part of the protobuf generated code. ```go func (m *GetResponse) GetMinuteQps() float64 ``` -------------------------------- ### TestRequest Type Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/testpb A sample request message type for testing. ```APIDOC ## Type TestRequest ### Description This message type is used for test requests, containing a string field 'lower' and an integer field 'repeat_count'. ### Fields - **lower** (string) - A string value, possibly in lowercase. - **repeat_count** (int32) - An integer specifying a repeat count. ### Constants - `Default_TestRequest_RepeatCount int32 = 1`: The default value for `repeat_count` is 1. ### Methods - `GetLower() string`: Retrieves the value of the 'lower' field. - `GetRepeatCount() int32`: Retrieves the value of the 'repeat_count' field. - `ProtoMessage()`: Marks the struct as a protobuf message. - `Reset()`: Resets the fields of the request message. - `String() string`: Returns a string representation of the request message. ``` -------------------------------- ### Implement String Method for TestMessage in Go Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/testpb Returns a string representation of the TestMessage message, useful for debugging and logging. ```go func (m *TestMessage) String() string ``` -------------------------------- ### Sink Creation Functions (Go) Source: https://pkg.go.dev/github.com/golang/groupcache/index Provides functions for creating Sink implementations. These include sinks for allocating byte slices, populating ByteViews, unmarshalling proto messages, populating string pointers, and truncating byte slices. ```Go func AllocatingByteSliceSink(dst *[]byte) Sink func ByteViewSink(dst *ByteView) Sink func ProtoSink(m proto.Message) Sink func StringSink(sp *string) Sink func TruncatingByteSliceSink(dst *[]byte) Sink ``` -------------------------------- ### NoPeers PickPeer Method Source: https://pkg.go.dev/github.com/golang/groupcache/index Implements the PickPeer method for the NoPeers type, always returning false as no peers are available. ```go func (NoPeers) PickPeer(key string) (peer ProtoGetter, ok bool) ``` -------------------------------- ### Define TestMessage Structure in Go Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/testpb Defines the TestMessage structure, used for testing purposes. It includes fields for 'name' and 'city', both as strings. ```go type TestMessage struct { Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty" City *string `protobuf:"bytes,2,opt,name=city" json:"city,omitempty" XXX_unrecognized []byte `json:"-" } ``` -------------------------------- ### Context Alias Source: https://pkg.go.dev/github.com/golang/groupcache/index An alias for context.Context for backward compatibility. ```go type Context = context.Context ``` -------------------------------- ### RegisterPerGroupPeerPicker Source: https://pkg.go.dev/github.com/golang/groupcache/index Registers a function for peer discovery that accepts the group name. This function is invoked once when the first group is initialized. Use this or RegisterPeerPicker, but not both. ```APIDOC ## RegisterPerGroupPeerPicker ### Description Registers the peer initialization function, which takes the groupName, to be used in choosing a PeerPicker. It is called once, when the first group is created. Either RegisterPeerPicker or RegisterPerGroupPeerPicker should be called exactly once, but not both. ### Method FUNC ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response None #### Success Response (200) None #### Response Example None ``` -------------------------------- ### TestMessage Type Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/testpb A sample message type for testing purposes. ```APIDOC ## Type TestMessage ### Description This is a sample message structure used for testing purposes. It contains fields for a name and a city. ### Fields - **name** (string) - The name field. - **city** (string) - The city field. ### Methods - `GetCity() string`: Retrieves the value of the city field. - `GetName() string`: Retrieves the value of the name field. - `ProtoMessage()`: Marks the struct as a protobuf message. - `Reset()`: Resets the fields of the message. - `String() string`: Returns a string representation of the message. ``` -------------------------------- ### String method for GetRequest - groupcachepb Go Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/groupcachepb Provides a string representation of the GetRequest message. Useful for debugging. ```go func (m *GetRequest) String() string ``` -------------------------------- ### ByteView Operations API Source: https://pkg.go.dev/github.com/golang/groupcache/index Details methods for interacting with ByteView objects, including length, reading, slicing, and string conversion. ```APIDOC ## Len ### Description Returns the length of the ByteView. ### Method GET ### Endpoint /byteview/len ### Parameters #### Query Parameters - **byteView** (ByteView) - Required - The ByteView object. ### Response #### Success Response (200) - **int** - The length of the ByteView. #### Response Example ```json { "length": 100 } ``` ## ReadAt ### Description Implements io.ReaderAt on the bytes in the ByteView. ### Method GET ### Endpoint /byteview/readat ### Parameters #### Query Parameters - **byteView** (ByteView) - Required - The ByteView object. - **p** ([]byte) - Required - The buffer to read into. - **off** (int64) - Required - The offset to start reading from. ### Response #### Success Response (200) - **n** (int) - The number of bytes read. - **err** (error) - An error if any occurred during reading. #### Response Example ```json { "n": 50, "err": null } ``` ## Reader ### Description Returns an io.ReadSeeker for the bytes in the ByteView. ### Method GET ### Endpoint /byteview/reader ### Parameters #### Query Parameters - **byteView** (ByteView) - Required - The ByteView object. ### Response #### Success Response (200) - **io.ReadSeeker** (object) - An io.ReadSeeker for the ByteView data. #### Response Example ```json { "reader": "ReadSeekerObject" } ``` ## Slice ### Description Slices the ByteView between the provided from and to indices. ### Method GET ### Endpoint /byteview/slice ### Parameters #### Query Parameters - **byteView** (ByteView) - Required - The ByteView object. - **from** (int) - Required - The starting index (inclusive). - **to** (int) - Required - The ending index (exclusive). ### Response #### Success Response (200) - **ByteView** - The sliced ByteView. #### Response Example ```json { "slicedByteView": "SlicedByteViewData" } ``` ## SliceFrom ### Description Slices the ByteView from the provided index until the end. ### Method GET ### Endpoint /byteview/slicefrom ### Parameters #### Query Parameters - **byteView** (ByteView) - Required - The ByteView object. - **from** (int) - Required - The starting index. ### Response #### Success Response (200) - **ByteView** - The sliced ByteView. #### Response Example ```json { "slicedByteView": "SlicedByteViewDataFromIndex" } ``` ## String ### Description Returns the data as a string, making a copy if necessary. ### Method GET ### Endpoint /byteview/string ### Parameters #### Query Parameters - **byteView** (ByteView) - Required - The ByteView object. ### Response #### Success Response (200) - **string** - The string representation of the ByteView data. #### Response Example ```json { "stringValue": "The data as a string" } ``` ## WriteTo ### Description Implements io.WriterTo on the bytes in the ByteView. ### Method POST ### Endpoint /byteview/writeto ### Parameters #### Request Body - **byteView** (ByteView) - Required - The ByteView object. - **w** (io.Writer) - Required - The writer to write the data to. ### Response #### Success Response (200) - **n** (int64) - The number of bytes written. - **err** (error) - An error if any occurred during writing. #### Response Example ```json { "n": 100, "err": null } ``` ``` -------------------------------- ### Implement GetServerIn Method in Go Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/testpb Provides a getter method for the 'ServerIn' field within the StatsResponse structure. This method returns the server input count as an int64. ```go func (m *StatsResponse) GetServerIn() int64 ``` -------------------------------- ### Implement GetTotalAlloc Method in Go Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/testpb Provides a getter method for the 'TotalAlloc' field within the StatsResponse structure. This method returns the total memory allocation as a uint64. ```go func (m *StatsResponse) GetTotalAlloc() uint64 ``` -------------------------------- ### Implement String Method for TestRequest in Go Source: https://pkg.go.dev/github.com/golang/groupcache/%40v0.0.0-20241129210726-2c02b8208cf8/testpb Returns a string representation of the TestRequest message, useful for debugging and logging. ```go func (m *TestRequest) String() string ``` -------------------------------- ### Group Management API Source: https://pkg.go.dev/github.com/golang/groupcache/index Provides functions for creating and retrieving cache groups. ```APIDOC ## GetGroup ### Description Retrieves a named group previously created with NewGroup. ### Method GET ### Endpoint /group/{name} ### Parameters #### Path Parameters - **name** (string) - Required - The name of the group to retrieve. ### Response #### Success Response (200) - **Group*** (object) - A pointer to the Group object if found, otherwise nil. #### Response Example ```json { "Group": "0xc00012a0e0" } ``` ## NewGroup ### Description Creates a coordinated group-aware Getter. The returned Getter ensures that only one Get call runs at once for a given key across all peer processes. Concurrent callers receive copies of the answer once the original Get completes. ### Method POST ### Endpoint /group ### Parameters #### Request Body - **name** (string) - Required - The unique name for the group. - **cacheBytes** (int64) - Required - The maximum number of bytes to use for the cache. - **getter** (Getter) - Required - The Getter interface implementation to load data. ### Request Example ```json { "name": "my-group", "cacheBytes": 1024, "getter": "GetterImplementation" } ``` ### Response #### Success Response (200) - ***Group** (object) - A pointer to the newly created Group object. #### Response Example ```json { "Group": "0xc00012a1a0" } ``` ``` -------------------------------- ### HTTPPool Peer Management Source: https://pkg.go.dev/github.com/golang/groupcache/index Provides methods for managing peers within the HTTP pool, including picking peers for keys and updating the list of available peers. ```APIDOC ## GET /websites/pkg_go_dev_github_com_golang_groupcache ### Description This section describes methods related to peer management in the HTTPPool. ### Method GET ### Endpoint /websites/pkg_go_dev_github_com_golang_groupcache ### Functions - **PickPeer(key string) (ProtoGetter, bool)**: Selects a peer responsible for the given key. - **Set(peers ...string)**: Updates the pool's list of peers. Each peer should be a valid base URL (e.g., "http://example.net:8000"). ```