cache

package
v0.0.0-...-2803a0f Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TeeReadCloser

func TeeReadCloser(r io.ReadCloser, w io.WriteCloser, callback func()) io.ReadCloser

TeeReadCloser is an io.TeeReader that also closes, and calls the callback after all streams are closed. The callback is only called if there were no errors closing the reader. This is so that if the connection is severed or the file is corrupted we don't cache. If there's a problem with the writer, it finishes reading still and skips the callback. That way if the disk is full we don't cache but the read is successful.

func WasResponseCached

func WasResponseCached(ctx *goproxy.ProxyCtx) bool

WasResponseCached returns true if the response was cached.

Types

type DB

type DB struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

DB contains the metadata of the disk cache

func New

func New(enabled bool, cacheDir string) (*DB, error)

New creates a new cache

func (*DB) OnRequest

func (d *DB) OnRequest(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response)

OnRequest checks to see if the response is cached, if so responds with the cached data.

func (*DB) OnResponse

func (d *DB) OnResponse(resp *http.Response, ctx *goproxy.ProxyCtx) *http.Response

OnResponse caches the data in the DB and writes the data to disk.

func (*DB) Statistics

func (d *DB) Statistics()

Statistics logs caching stats.

func (*DB) WriteToDisk

func (d *DB) WriteToDisk() error

WriteToDisk outputs the db in the cache directory for scenario use.

type Entry

type Entry struct {
	Status          int         `yaml:"status"`
	FilePath        string      `yaml:"filePath"`
	ResponseHeaders http.Header `yaml:"responseHeaders,omitempty"`

	// only set with PROXY_DEBUG_HEADERS=true
	RequestHeaders http.Header `yaml:"requestHeaders,omitempty"`
}

Entry is an entry of the DB

type Key

type Key struct {
	Method     string `yaml:"method"`
	URL        string `yaml:"URL"`
	HeaderHash string `yaml:"headerHash,omitempty"`
	BodyHash   string `yaml:"bodyHash,omitempty"`
}

Key is the key type used in the DB map

type Out

type Out struct {
	Key
	*Entry
}

Out is used to serialize the DB

Jump to

Keyboard shortcuts

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