readcache

package
v1.3.0-dev.5 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package readcache revalidates the GET requests of an HTTP client you build yourself, for routes no forgeapi operation covers, with the same read cache every forgeapi client keeps. The guide is docs/read-cache.md, at https://github.com/cplieger/forgeapi/blob/dev/docs/read-cache.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures a Transport.

func WithFreeNotModified

func WithFreeNotModified(free bool) Option

WithFreeNotModified states whether the server bills nothing for a 304 answering a conditional request that carries an Authorization header, as GitHub's REST API does. It decides only what forgeapi.ReadCacheState.Saved counts.

Default: false, so Saved counts nothing.

func WithHeldFields

func WithHeldFields(names ...string) Option

WithHeldFields names the response header fields the caller reads from a served answer, such as Link for paging. A held field the 304 carries takes the 304's value; one it omits keeps the held value, which the 304 did not confirm. A field sent on several lines keeps each. Every other field of a served answer is the 304's own. Each call replaces the last.

Default: none.

func WithMaxBytes

func WithMaxBytes(maxBytes int64) Option

WithMaxBytes bounds the bytes the cache holds, evicting the least recently used entry first. Zero holds nothing and adds no validator, though a 304 to a GET is still sent once more without one. A negative maxBytes is refused by NewTransport with forgeapi.CodeBudgetInvalid.

Default: forgeapi.DefaultReadCacheBytes.

type Transport

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

Transport is an http.RoundTripper that revalidates the GET requests it carries against what it read before, and answers one from a held answer only where the server answers its validator with 304 Not Modified. A served answer reaches the caller as a 200 with the held body. It is safe for concurrent use.

func NewTransport

func NewTransport(next http.RoundTripper, opts ...Option) (*Transport, error)

NewTransport builds a Transport that sends every request through next, which is what an attempt observer wraps to see each request that reaches the server. An answer from next is served from or kept only where its Request is the request next was given, as http.Transport reports it, so a round tripper that sets a credential or another request header wraps the Transport instead. It refuses a nil next with forgeapi.CodeConnectionInvalid and a negative WithMaxBytes with forgeapi.CodeBudgetInvalid.

func (*Transport) CloseIdleConnections

func (t *Transport) CloseIdleConnections()

CloseIdleConnections closes next's idle connections where next has a CloseIdleConnections method, so http.Client.CloseIdleConnections reaches them.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip sends r, revalidating it where it is a GET carrying no validator of its own.

func (*Transport) State

func (t *Transport) State() forgeapi.ReadCacheState

State is what the cache has done since it was built, and the bytes it holds now.

Jump to

Keyboard shortcuts

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