client

package
v12.2.11 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: BSD-3-Clause Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Client = &http.Client{Timeout: cfg.RequestCacheTimeout}

Client is used inside the global Request function this client is an exported to give you a freedom of change its Transport, Timeout and so on(in case of ssl)

DefaultRuleSet is a list of the default pre-cache validators which exists in ALL handlers, local and remote.

Functions

func GetKey added in v12.2.0

func GetKey(ctx *context.Context) string

GetKey returns the entry key for the current page.

func NoCache

func NoCache(ctx *context.Context)

NoCache disables the cache for a particular request, can be used as a middleware or called manually from the handler.

func SetKey added in v12.2.0

func SetKey(ctx *context.Context, key string)

SetKey sets a custom entry key for cached pages. See root package-level `WithKey` instead.

Types

type ClientHandler

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

ClientHandler is the client-side handler for each of the cached route paths's response register one client handler per route.

it's just calls a remote cache service server/handler, which may lives on other, external machine.

func NewClientHandler

func NewClientHandler(bodyHandler context.Handler, life time.Duration, remote string) *ClientHandler

NewClientHandler returns a new remote client handler which asks the remote handler the cached entry's response with a GET request, or add a response with POST request these all are done automatically, users can use this handler as they use the local.go/NewHandler

the ClientHandler is useful when user wants to apply horizontal scaling to the app and has a central http server which handles

func (*ClientHandler) AddRule

func (h *ClientHandler) AddRule(r rule.Rule) *ClientHandler

AddRule adds a rule in the chain, the default rules are executed first.

returns itself.

func (*ClientHandler) Rule

func (h *ClientHandler) Rule(r rule.Rule) *ClientHandler

Rule sets the ruleset for this handler, see internal/net/http/ruleset.go for more information.

returns itself.

func (*ClientHandler) ServeHTTP

func (h *ClientHandler) ServeHTTP(ctx *context.Context)

ServeHTTP , or remote cache client whatever you like, it's the client-side function of the ServeHTTP sends a request to the server-side remote cache Service and sends the cached response to the frontend client it is used only when you achieved something like horizontal scaling (separate machines) look ../remote/remote.ServeHTTP for more

if cache din't find then it sends a POST request and save the bodyHandler's body to the remote cache.

It takes 3 parameters the first is the remote address (it's the address you started your http server which handled by the Service.ServeHTTP) the second is the handler (or the mux) you want to cache and the third is the, optionally, cache expiration, which is used to set cache duration of this specific cache entry to the remote cache service if <=minimumAllowedCacheDuration then the server will try to parse from "cache-control" header

client-side function

type Handler

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

Handler the local cache service handler contains the original response, the memory cache entry and the validator for each of the incoming requests and post responses

func NewHandler

func NewHandler(maxAgeFunc MaxAgeFunc) *Handler

NewHandler returns a new Server-side cached handler for the "bodyHandler" which expires every "expiration".

func (*Handler) AddRule

func (h *Handler) AddRule(r rule.Rule) *Handler

AddRule adds a rule in the chain, the default rules are executed first.

returns itself.

func (*Handler) MaxAge added in v12.2.8

func (h *Handler) MaxAge(fn MaxAgeFunc) *Handler

MaxAge customizes the expiration duration for this handler.

func (*Handler) Rule

func (h *Handler) Rule(r rule.Rule) *Handler

Rule sets the ruleset for this handler.

returns itself.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(ctx *context.Context)

func (*Handler) Store added in v12.2.8

func (h *Handler) Store(store entry.Store) *Handler

Store sets a custom store for this handler.

type MaxAgeFunc added in v12.2.8

type MaxAgeFunc func(*context.Context) time.Duration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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