cache

package
v0.0.0-...-9ed1330 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

The campwiz package contains all of the brains for querying campsites.

Index

Constants

This section is empty.

Variables

View Source
var (

	// How long to cache by default: needs to be less than session cookie (12 hours is too long)
	RecommendedMaxAge = 4 * time.Hour
)

Functions

func New

func New(c Config) (*diskv.Diskv, error)

New returns a new cache (hardcoded to diskv, for the moment)

Types

type Config

type Config struct {
	MaxAge time.Duration
}

type Request

type Request struct {
	// Method type
	Method string
	// URL
	URL string
	// Referrer
	Referrer string
	// CookieJar
	Jar *cookiejar.Jar
	// Cookies
	Cookies []*http.Cookie
	// POST form values
	Form url.Values
	// Maximum age of content.
	MaxAge  time.Duration
	Headers map[string]string
	// POST info
	ContentType string
	Body        []byte
}

Request defines what can be passed in as a request

func (Request) Key

func (r Request) Key() string

Key returns a cache-key.

type Response

type Response struct {
	// URL result is from
	URL string
	// Status Code
	StatusCode int
	// HTTP headers
	Header http.Header
	// Cookies are the cookies that came with the request.
	Cookies []*http.Cookie
	// Body is the entire HTTP message body.
	Body []byte
	// MTime is when this value was last updated in the cache.
	MTime time.Time
	// If entry was served from cache
	Cached bool
}

Response defines which data may be cached for an HTTP response.

func Fetch

func Fetch(req Request, cs Store) (Response, error)

Fetch wraps http.Get/http.Post behind a persistent ca

type Store

type Store interface {
	Read(string) ([]byte, error)
	Write(string, []byte) error
}

Jump to

Keyboard shortcuts

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