cache

package
v0.72.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package cache provides a cache control and implementation components for http routes.

Index

Constants

View Source
const (

	// HeaderCacheControl is the Header key for cache related values.
	// note : it is case-sensitive.
	HeaderCacheControl = "Cache-Control"
	// HeaderETagHeader is the constant representing the Etag http header.
	HeaderETagHeader = "Etag"
)

Variables

View Source
var NowSeconds = func() int64 {
	return time.Now().Unix()
}

NowSeconds returns the current unix timestamp in seconds.

Functions

func Handler

func Handler(w http.ResponseWriter, r *http.Request, rc *RouteCache, httpHandler http.Handler) error

Handler will wrap the handler func with the route cache abstraction.

Types

type Age

type Age struct {
	// Min adds a minimum age threshold for the client controlled cache responses.
	// This will avoid cases where a single client with high request rate and no cache control headers might effectively disable the cache
	// This means that if this parameter is missing (e.g. is equal to '0' , the cache can effectively be made obsolete in the above scenario).
	Min time.Duration
	// Max adds a maximum age for the cache responses. Which effectively works as a time-to-live wrapper on top of the cache.
	Max time.Duration
}

Age defines the route cache life-time boundaries for cached objects.

type RouteCache

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

RouteCache is the builder needed to build a cache for the corresponding route.

func NewRouteCache

func NewRouteCache(ttlCache cache.TTLCache, age Age) (*RouteCache, []error)

NewRouteCache creates a new cache implementation for an http route.

Jump to

Keyboard shortcuts

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