gocached

package
v0.0.0-...-75febc3 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: BSD-3-Clause Imports: 33 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JWTIssuerConfig

type JWTIssuerConfig struct {
	// Issuer is the OIDC issuer URL. It must be a reachable HTTP(S) server
	// that serves its JWKS via a URL discoverable at
	// /.well-known/openid-configuration.
	Issuer string

	// RequiredClaims are claims that any JWT from this issuer must have to
	// start a session. All key-value pairs must match exactly.
	RequiredClaims map[string]string

	// GlobalWriteClaims are claims that a JWT from this issuer must have to
	// write to the cache's global namespace. It should be a superset of
	// RequiredClaims.
	GlobalWriteClaims map[string]string
}

JWTIssuerConfig configures a single OIDC issuer for JWT-based authentication.

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) Close

func (srv *Server) Close() error

Close shuts down the server, stopping background goroutines and closing the database.

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 WithJWTAuth

func WithJWTAuth(issuers ...JWTIssuerConfig) ServerOption

WithJWTAuth enables JWT-based authentication for the server. Each 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 issuer's required claims to start a session. No requests are allowed without authentication if JWT auth is enabled. It can be called multiple times; configs accumulate.

func WithLogf

func WithLogf(logf logger.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.

Directories

Path Synopsis
internal
jwt

Jump to

Keyboard shortcuts

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