httpcache: github.com/geekypanda/httpcache/fhttp Index | Files | Directories

package fhttp

import "github.com/geekypanda/httpcache/fhttp"

Index

Package Files

client.go handler.go ruleset.go utils.go

Variables

var ClientFasthttp = &fasthttp.Client{WriteTimeout: cfg.RequestCacheTimeout, ReadTimeout: cfg.RequestCacheTimeout}

ClientFasthttp is used inside the global RequestFasthttp function this client is an exported variable because the maybe the remote cache service is running behind ssl, in that case you are able to set a Transport inside it

var DefaultRuleSet = rule.Chained(

    rule.HeaderClaim(ruleset.AuthorizationRule),

    rule.HeaderClaim(ruleset.MustRevalidateRule),
    rule.HeaderClaim(ruleset.ZeroMaxAgeRule),

    rule.Header(ruleset.NoCacheRule, ruleset.NoCacheRule),
)

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

func GetMaxAge Uses

func GetMaxAge(reqCtx *fasthttp.RequestCtx) entry.LifeChanger

GetMaxAge parses the "Cache-Control" header and returns a LifeChanger which can be passed to the response's Reset

func NoCache Uses

func NoCache(reqCtx *fasthttp.RequestCtx)

NoCache called when a particular handler is not valid for cache. If this function called inside a handler then the handler is not cached.

type ClientHandler Uses

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 lives on other, external machine.

func NewClientHandler Uses

func NewClientHandler(bodyHandler fasthttp.RequestHandler, 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 Uses

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 Uses

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

Rule sets the ruleset for this handler. returns itself.

func (*ClientHandler) ServeHTTP Uses

func (h *ClientHandler) ServeHTTP(reqCtx *fasthttp.RequestCtx)

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 Uses

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

Handler the fasthttp cache service handler

func NewHandler Uses

func NewHandler(bodyHandler fasthttp.RequestHandler,
    expireDuration time.Duration) *Handler

NewHandler returns a new cached handler

func (*Handler) AddRule Uses

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) Rule Uses

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

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

returns itself.

func (*Handler) ServeHTTP Uses

func (h *Handler) ServeHTTP(reqCtx *fasthttp.RequestCtx)

Directories

PathSynopsis
rule

Package fhttp imports 7 packages (graph) and is imported by 3 packages. Updated 2018-02-16. Refresh now. Tools for package owners.