Documentation ¶
Index ¶
- Constants
- type CacheType
- type Config
- type Entry
- type HTTPCache
- type Handler
- func (Handler) CaddyModule() caddy.ModuleInfo
- func (h *Handler) Cleanup() error
- func (h *Handler) Provision(ctx caddy.Context) error
- func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error
- func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
- func (h *Handler) Validate() error
- type HeaderRuleMatcher
- type PathRuleMatcher
- type PurgePayload
- type Response
- func (r *Response) Clean() error
- func (r *Response) Close() error
- func (r *Response) Flush()
- func (r *Response) GetReader() (io.ReadCloser, error)
- func (r *Response) Header() http.Header
- func (r *Response) SetBody(body backends.Backend)
- func (r *Response) WaitClose()
- func (r *Response) WaitHeaders()
- func (r *Response) Write(buf []byte) (int, error)
- func (r *Response) WriteHeader(code int)
- type RuleMatcher
- type RuleMatcherRawWithType
- type RuleMatcherType
- type URLLock
Constants ¶
const ( BYTE = 1 << (iota * 10) KB MB GB )
BYTE represents the num of byte 1MB = 2^10 BYTE 1GB = 2^10 MB
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheType ¶
type CacheType string
CacheType is the type of cache which means the backend for storing cache content.
type Config ¶
type Config struct { Type CacheType `json:"type,omitempty"` StatusHeader string `json:"status_header,omitempty"` DefaultMaxAge time.Duration `json:"default_max_age,omitempty"` LockTimeout time.Duration `json:"lock_timeout,omitempty"` RuleMatchersRaws []RuleMatcherRawWithType `json:"rule_matcher_raws,omitempty"` RuleMatchers []RuleMatcher `json:"-"` CacheBucketsNum int `json:"cache_buckets_num,omitempty"` CacheMaxMemorySize int `json:"cache_max_memory_size,omitempty"` Path string `json:"path,omitempty"` CacheKeyTemplate string `json:"cache_key_template,omitempty"` RedisConnectionSetting string `json:"redis_connection_setting,omitempty"` }
Config is the configuration for cache process
type Entry ¶
type Entry struct { Request *http.Request Response *Response // contains filtered or unexported fields }
Entry consists of a cache key and one or more response corresponding to the prior requests. https://httpwg.org/specs/rfc7234.html#caching.overview
func NewEntry ¶
NewEntry creates a new Entry for the given request and response and it also calculates whether it is public or not
func (*Entry) WriteBodyTo ¶
func (e *Entry) WriteBodyTo(w http.ResponseWriter) error
WriteBodyTo sends the body to the http.ResponseWritter
type HTTPCache ¶
type HTTPCache struct {
// contains filtered or unexported fields
}
HTTPCache is a http cache for http request which is focus on static files
func NewHTTPCache ¶
NewHTTPCache new a HTTPCache to handle cache entries
type Handler ¶
type Handler struct { Config *Config `json:"config,omitempty"` Cache *HTTPCache `json:"-"` URLLocks *URLLock `json:"-"` DistributedRaw json.RawMessage `json:"distributed,omitempty" caddy:"namespace=distributed inline_key=distributed"` Distributed *distributed.ConsulService `json:"-"` // contains filtered or unexported fields }
Handler is a http handler as a middleware to cache the response
func (Handler) CaddyModule ¶
func (Handler) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information
func (*Handler) UnmarshalCaddyfile ¶
UnmarshalCaddyfile sets up the handler from Caddyfile
:4000 { reverse_proxy yourserver:5000 http_cache { match_path /assets match_header Content-Type image/jpg image/png status_header X-Cache-Status default_max_age 15m path /tmp/caddy-cache distributed consul { service_name addr } } }
type HeaderRuleMatcher ¶
HeaderRuleMatcher determines whether the request's header is matched.
type PathRuleMatcher ¶
type PathRuleMatcher struct {
Path string `json:"path"`
}
PathRuleMatcher determines whether the request's path is matched.
type PurgePayload ¶ added in v0.1.0
type PurgePayload struct { Method string `json:"method"` Host string `json:"host"` URI string `json:"uri"` // contains filtered or unexported fields }
PurgePayload holds the field which will be unmarshalled from the request's body NOTE: the format of URI can contains the query param. ex. when the client send a delete request with the body
{ "method": "GET", "hots": "example.com", "uri": "/static?ext=txt", }
type Response ¶
type Response struct { Code int HeaderMap http.Header IsFirstByteWritten bool // contains filtered or unexported fields }
Response encapsulates the entry
func (*Response) Close ¶
Close indicate the data is completely written to the body so that we can close it.
func (*Response) Flush ¶
func (r *Response) Flush()
Flush flushes the backend's storage (currently, only file storage need to call this)
func (*Response) GetReader ¶
func (r *Response) GetReader() (io.ReadCloser, error)
GetReader gets the reader from the setted backend
func (*Response) WaitClose ¶
func (r *Response) WaitClose()
WaitClose waits the response to be closed.
func (*Response) WaitHeaders ¶
func (r *Response) WaitHeaders()
WaitHeaders waits the header to be written
func (*Response) Write ¶
Write writes the upstream's content in the backend's storage this will wait the body(backend) is set
func (*Response) WriteHeader ¶
WriteHeader keeps the upstream response header
type RuleMatcher ¶
type RuleMatcher interface {
// contains filtered or unexported methods
}
RuleMatcher determines whether the request should be cached or not.
type RuleMatcherRawWithType ¶
type RuleMatcherRawWithType struct { Type RuleMatcherType Data json.RawMessage }
RuleMatcherRawWithType stores the marshal content for unmarshalling in provision stage
type RuleMatcherType ¶
type RuleMatcherType string
RuleMatcherType specifies the type of matching rule to cache.
const ( MatcherTypePath RuleMatcherType = "path" MatcherTypeHeader RuleMatcherType = "header" )
the following list the different way to decide the request whether is matched or not to be cached it's response.