Documentation
¶
Index ¶
- Constants
- Variables
- func Middleware(c *configv1.Middleware) (middleware.Middleware, func(), error)
- type Caching
- type Duration
- type FileChangeOption
- type FileChangedProcessor
- type FillRangeOption
- type PrefetchOption
- type PrefetchProcessor
- type Processor
- type ProcessorChain
- func (pc *ProcessorChain) Lookup(caching *Caching, req *http.Request) (bool, error)
- func (pc *ProcessorChain) PostRequest(caching *Caching, req *http.Request, resp *http.Response) (*http.Response, error)
- func (pc *ProcessorChain) PreRequest(caching *Caching, req *http.Request) (*http.Request, error)
- func (pc *ProcessorChain) String() string
- type RefreshOption
- type RevalidateProcessor
- type StateProcessor
- type VaryOption
- type VaryProcessor
Constants ¶
const BYPASS = "BYPASS"
Variables ¶
var ( ErrHeaderNoMatchVaryKey = errors.New("header no match vary key") ErrHeaderNoMatchVaryData = errors.New("header no match vary data") // ErrVarySizeLimited indicates the number of Vary versions has exceeded the maximum limit. ErrVarySizeLimited = errors.New("vary size exceed limit") // ErrVaryDowngradeNormal indicates the cache has been downgraded from Vary to normal cache. ErrVaryDowngradeNormal = errors.New("vary downgrade to normal cache") )
Functions ¶
func Middleware ¶
func Middleware(c *configv1.Middleware) (middleware.Middleware, func(), error)
Middleware initializes a middleware component based on the provided configuration and returns the middleware logic.
Types ¶
type FileChangeOption ¶
type FileChangeOption func(r *FileChangedProcessor)
FileChangeOption represents a functional option for configuring a FileChangedProcessor.
type FileChangedProcessor ¶
type FileChangedProcessor struct {
}
FileChangedProcessor handles the detection and processing of file changes during cache operations.
func (*FileChangedProcessor) Lookup ¶
Lookup determines the validity of a file change based on the provided caching mechanism and HTTP request.
func (*FileChangedProcessor) PostRequest ¶
func (r *FileChangedProcessor) PostRequest(c *Caching, req *http.Request, resp *http.Response) (*http.Response, error)
PostRequest processes the HTTP response after it is received, checking for file changes and metadata mismatches. It validates content length, ETag, and Last-Modified headers, and handles discrepancies by updating the cache state.
func (*FileChangedProcessor) PreRequest ¶
PreRequest processes the HTTP request before it is sent, potentially modifying it, and returns the updated request.
type FillRangeOption ¶
type FillRangeOption func(f *fillRange)
func WithChunkSize ¶
func WithChunkSize(chunkSize uint64) FillRangeOption
func WithFillRangePercent ¶
func WithFillRangePercent(fillRangePercent int) FillRangeOption
type PrefetchOption ¶
type PrefetchOption func(r *PrefetchProcessor)
type PrefetchProcessor ¶
type PrefetchProcessor struct{}
func (*PrefetchProcessor) PostRequest ¶
func (*PrefetchProcessor) PreRequest ¶
type Processor ¶
type Processor interface {
// Lookup checks if the request hits the cache.
Lookup(caching *Caching, req *http.Request) (bool, error)
// PreRequest processes the request before sending it to the origin server.
PreRequest(caching *Caching, req *http.Request) (*http.Request, error)
// PostRequest processes the response received from the origin server.
PostRequest(caching *Caching, req *http.Request, resp *http.Response) (*http.Response, error)
}
Processor defines the interface for caching processor middleware.
func NewFileChangedProcessor ¶
func NewFileChangedProcessor(opts ...FileChangeOption) Processor
NewFileChangedProcessor creates and returns a new instance of FileChangedProcessor with optional configuration options.
func NewFillRangeProcessor ¶
func NewFillRangeProcessor(opts ...FillRangeOption) Processor
func NewPrefetchProcessor ¶
func NewPrefetchProcessor(opts ...PrefetchOption) Processor
func NewRevalidateProcessor ¶
func NewRevalidateProcessor(opts ...RefreshOption) Processor
func NewStateProcessor ¶
func NewStateProcessor() Processor
type ProcessorChain ¶
type ProcessorChain []Processor
ProcessorChain represents a chain of caching processors.
func NewProcessorChain ¶
func NewProcessorChain(processors ...Processor) *ProcessorChain
NewProcessorChain creates a new ProcessorChain with the given processors.
func (*ProcessorChain) Lookup ¶
Lookup iterates through the processor chain to check for a cache hit.
func (*ProcessorChain) PostRequest ¶
func (pc *ProcessorChain) PostRequest(caching *Caching, req *http.Request, resp *http.Response) (*http.Response, error)
PostRequest processes the response through the processor chain after receiving it from the origin server.
func (*ProcessorChain) PreRequest ¶
PreRequest processes the request through the processor chain before sending it to the origin server.
func (*ProcessorChain) String ¶
func (pc *ProcessorChain) String() string
String returns a string representation of the processor chain.
type RefreshOption ¶
type RefreshOption func(r *RevalidateProcessor)
type RevalidateProcessor ¶
type RevalidateProcessor struct{}
func (*RevalidateProcessor) PostRequest ¶
func (*RevalidateProcessor) PreRequest ¶
type StateProcessor ¶
type StateProcessor struct{}
func (*StateProcessor) PostRequest ¶
func (s *StateProcessor) PostRequest(c *Caching, req *http.Request, resp *http.Response) (*http.Response, error)
PostRequest implements Processor.
func (*StateProcessor) PreRequest ¶
PreRequest implements Processor.
type VaryOption ¶
type VaryOption func(r *VaryProcessor)
func WithVaryIgnoreKeys ¶
func WithVaryIgnoreKeys(keys ...string) VaryOption
WithVaryIgnoreKeys specifies header keys to be ignored during Vary processing.
func WithVaryMaxLimit ¶
func WithVaryMaxLimit(limit int) VaryOption
WithVaryMaxLimit sets the maximum number of Vary versions allowed per URL.
type VaryProcessor ¶
type VaryProcessor struct {
// contains filtered or unexported fields
}
func NewVaryProcessor ¶
func NewVaryProcessor(opts ...VaryOption) *VaryProcessor
NewVaryProcessor creates a new VaryProcessor with the given options. Default configuration:
- maxLimit: 100 (maximum Vary versions per URL)
func (*VaryProcessor) Lookup ¶
Lookup checks if a cached response exists for the given request. It returns true if a matching Vary cache entry is found, false otherwise.
The lookup process:
- Check if the request has no-cache directive
- Verify if the cached object has Vary index
- Find the matching Vary cache based on request headers
func (*VaryProcessor) PostRequest ¶
func (v *VaryProcessor) PostRequest(caching *Caching, req *http.Request, resp *http.Response) (*http.Response, error)
PostRequest processes the response from the origin server and handles Vary caching. It converts the response to a Vary-aware cache structure if the response contains Vary headers.
func (*VaryProcessor) PreRequest ¶
PreRequest performs pre-processing before the request is forwarded to the origin. Currently, this is a no-op for VaryProcessor.