Documentation
¶
Overview ¶
The gocached package provides an HTTP server daemon that go-cacher can hit. It does cache tiering and evicts old large things from disk, and can fetch metadata and object contents from peer cache servers.
It uses sqlite (the pure Go modernc.org/sqlite driver) to store metadata and indexes.
It speaks the same protocol as go-cacher-server, but requires the "Want-Object: 1" header variant on the GET request.
GET /action/<actionID-hex> Want-Object: 1 200 OK Content-Type: application/octet-stream Content-Length: 1234 Go-Output-Id: xxxxxxxxxxx <object-id-contents>
And to insert an object:
PUT /<actionID>/<outputID> Content-Length: 1234 <bytes>
Index ¶
- type Server
- type ServerOption
- func WithDir(dir string) ServerOption
- func WithGlobalNamespaceJWTClaims(claims map[string]string) ServerOption
- func WithJWTAuth(issuer string, claims map[string]string) ServerOption
- func WithLogf(logf logf) ServerOption
- func WithMaxAge(maxAge time.Duration) ServerOption
- func WithMaxSize(maxSize int64) ServerOption
- func WithShutdownCtx(ctx context.Context) ServerOption
- func WithVerbose(verbose bool) ServerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server implements a gocached server. Use NewServer to create and start a valid instance.
func NewServer ¶
func NewServer(opts ...ServerOption) (*Server, error)
NewServer creates and starts a new gocached Server that is ready to serve requests. It defaults to requiring no authentication and storing its data in the OS user cache directory under $XDG_CACHE_HOME/gocached or equivalent.
func (*Server) ServeHTTP ¶
func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements gocached's API via http.Handler.
func (*Server) ServeHTTPDebug ¶
func (srv *Server) ServeHTTPDebug(w http.ResponseWriter, r *http.Request)
ServeHTTPDebug serves debug HTTP endpoints. It is unauthenticated, so should only be used on a separate debug listener.
type ServerOption ¶
type ServerOption func(*Server)
ServerOption configures a gocached Server.
func WithDir ¶
func WithDir(dir string) ServerOption
WithDir sets the directory where the server stores its data. Defaults to the OS user cache directory under $XDG_CACHE_HOME/gocached or equivalent.
func WithGlobalNamespaceJWTClaims ¶
func WithGlobalNamespaceJWTClaims(claims map[string]string) ServerOption
WithGlobalNamespaceJWTClaims sets additional claims that a JWT must have to write to the cache's global namespace. It should be a superset of the claims provided to WithJWTAuth.
func WithJWTAuth ¶
func WithJWTAuth(issuer string, claims map[string]string) ServerOption
WithJWTAuth enables JWT-based authentication for the server. The issuer must be a reachable HTTP(S) server that serves its JWKS via a URL discoverable at /.well-known/openid-configuration, and any JWT presented to the server must exactly match the provided claims to start a session. No requests are allowed without authentication if JWT auth is enabled.
func WithLogf ¶
func WithLogf(logf logf) ServerOption
WithLogf sets a custom logging function for the server. Defaults to log.Printf.
func WithMaxAge ¶
func WithMaxAge(maxAge time.Duration) ServerOption
WithMaxAge sets the maximum age of objects in the cache. Objects older than this duration will be cleaned periodically. Defaults to 0, which means no limit.
func WithMaxSize ¶
func WithMaxSize(maxSize int64) ServerOption
WithMaxSize sets the maximum size of the cache in bytes. Defaults to 0, which means no limit.
func WithShutdownCtx ¶
func WithShutdownCtx(ctx context.Context) ServerOption
WithShutdownCtx sets the context used to signal server shutdown. Defaults to context.Background().
func WithVerbose ¶
func WithVerbose(verbose bool) ServerOption
WithVerbose enables verbose logging for the server. Defaults to false.