Documentation
¶
Index ¶
- Constants
- Variables
- func MappingElection(provider Storer, item []byte, req *http.Request, validator *Revalidator, ...) (resultFresh *http.Response, resultStale *http.Response, e error)
- func MappingElectionEntries(provider Storer, entries map[string][]byte, req *http.Request, ...) (*http.Response, *http.Response, error)
- func MappingEntry(now, freshTime, staleTime time.Time, variedHeaders http.Header, ...) ([]byte, error)
- func MappingUpdater(key string, item []byte, logger Logger, now, freshTime, staleTime time.Time, ...) (val []byte, e error)
- func RegisterStorage(s Storer)
- func ResetRegisteredStorages()
- func ValidateETagFromHeader(etag string, validator *Revalidator)
- type CacheProvider
- type Configuration
- type KeyIndex
- func (*KeyIndex) Descriptor() ([]byte, []int)deprecated
- func (x *KeyIndex) GetEtag() string
- func (x *KeyIndex) GetFreshTime() *timestamppb.Timestamp
- func (x *KeyIndex) GetRealKey() string
- func (x *KeyIndex) GetStaleTime() *timestamppb.Timestamp
- func (x *KeyIndex) GetStoredAt() *timestamppb.Timestamp
- func (x *KeyIndex) GetVariedHeaders() map[string]*KeyIndexStringList
- func (*KeyIndex) ProtoMessage()
- func (x *KeyIndex) ProtoReflect() protoreflect.Message
- func (x *KeyIndex) Reset()
- func (x *KeyIndex) String() string
- type KeyIndexStringList
- func (*KeyIndexStringList) Descriptor() ([]byte, []int)deprecated
- func (x *KeyIndexStringList) GetHeaderValue() []string
- func (*KeyIndexStringList) ProtoMessage()
- func (x *KeyIndexStringList) ProtoReflect() protoreflect.Message
- func (x *KeyIndexStringList) Reset()
- func (x *KeyIndexStringList) String() string
- type Logger
- type MappingWalker
- type Revalidator
- type SetStorer
- type StorageMapper
- type Storer
Constants ¶
const ( DISABLE_VARY_CTX = "storages_bypass_vary" MappingKeyPrefix = "IDX_" SurrogateKeyPrefix = "SURROGATE_" )
const MaxMappingSize = 1 << 20
MaxMappingSize bounds the legacy mapping blobs a storer is willing to decode or migrate; larger values are dropped instead of materialized.
Variables ¶
var File_storage_proto protoreflect.FileDescriptor
Lz4WriterPool pools lz4 writers, which are safe to reuse once Close has flushed the frame. Callers must Reset the writer before use and only return it to the pool after Close. Readers must never be pooled this way: a pooled reader escapes through http.Response.Body and would be recycled while another goroutine still reads from it.
Functions ¶
func MappingElection ¶
func MappingElectionEntries ¶ added in v0.0.20
func MappingElectionEntries(provider Storer, entries map[string][]byte, req *http.Request, validator *Revalidator, logger Logger) (*http.Response, *http.Response, error)
MappingElectionEntries elects a fresh/stale response from per-variant entries, where each value is one marshalled KeyIndex as stored by storers keeping one field per varied key instead of one blob per base key.
func MappingEntry ¶ added in v0.0.20
func MappingEntry(now, freshTime, staleTime time.Time, variedHeaders http.Header, etag, realKey string) ([]byte, error)
MappingEntry marshals a single mapping entry for storers that keep one value per varied key instead of one blob per base key.
func MappingUpdater ¶
func RegisterStorage ¶
func RegisterStorage(s Storer)
func ResetRegisteredStorages ¶ added in v0.0.2
func ResetRegisteredStorages()
func ValidateETagFromHeader ¶
func ValidateETagFromHeader(etag string, validator *Revalidator)
Types ¶
type CacheProvider ¶
type CacheProvider struct {
// URL to connect to the storage system.
URL string `json:"url" yaml:"url"`
// Path to the configuration file.
Path string `json:"path" yaml:"path"`
// Declare the cache provider directly in the Souin configuration.
Configuration any `json:"configuration" yaml:"configuration"`
}
CacheProvider config.
type Configuration ¶
type Configuration struct {
Provider CacheProvider `json:"provider"`
Stale time.Duration `json:"stale"`
}
type KeyIndex ¶ added in v0.0.6
type KeyIndex struct {
StoredAt *timestamppb.Timestamp `protobuf:"bytes,1,opt,name=stored_at,json=storedAt,proto3" json:"stored_at,omitempty"`
FreshTime *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=fresh_time,json=freshTime,proto3" json:"fresh_time,omitempty"`
StaleTime *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=stale_time,json=staleTime,proto3" json:"stale_time,omitempty"`
VariedHeaders map[string]*KeyIndexStringList `` /* 188-byte string literal not displayed */
Etag string `protobuf:"bytes,5,opt,name=etag,proto3" json:"etag,omitempty"`
RealKey string `protobuf:"bytes,6,opt,name=real_key,json=realKey,proto3" json:"real_key,omitempty"`
// contains filtered or unexported fields
}
func (*KeyIndex) Descriptor
deprecated
added in
v0.0.6
func (*KeyIndex) GetFreshTime ¶ added in v0.0.6
func (x *KeyIndex) GetFreshTime() *timestamppb.Timestamp
func (*KeyIndex) GetRealKey ¶ added in v0.0.6
func (*KeyIndex) GetStaleTime ¶ added in v0.0.6
func (x *KeyIndex) GetStaleTime() *timestamppb.Timestamp
func (*KeyIndex) GetStoredAt ¶ added in v0.0.6
func (x *KeyIndex) GetStoredAt() *timestamppb.Timestamp
func (*KeyIndex) GetVariedHeaders ¶ added in v0.0.6
func (x *KeyIndex) GetVariedHeaders() map[string]*KeyIndexStringList
func (*KeyIndex) ProtoMessage ¶ added in v0.0.6
func (*KeyIndex) ProtoMessage()
func (*KeyIndex) ProtoReflect ¶ added in v0.0.6
func (x *KeyIndex) ProtoReflect() protoreflect.Message
type KeyIndexStringList ¶ added in v0.0.6
type KeyIndexStringList struct {
HeaderValue []string `protobuf:"bytes,1,rep,name=header_value,json=headerValue,proto3" json:"header_value,omitempty"`
// contains filtered or unexported fields
}
func (*KeyIndexStringList) Descriptor
deprecated
added in
v0.0.6
func (*KeyIndexStringList) Descriptor() ([]byte, []int)
Deprecated: Use KeyIndexStringList.ProtoReflect.Descriptor instead.
func (*KeyIndexStringList) GetHeaderValue ¶ added in v0.0.6
func (x *KeyIndexStringList) GetHeaderValue() []string
func (*KeyIndexStringList) ProtoMessage ¶ added in v0.0.6
func (*KeyIndexStringList) ProtoMessage()
func (*KeyIndexStringList) ProtoReflect ¶ added in v0.0.6
func (x *KeyIndexStringList) ProtoReflect() protoreflect.Message
func (*KeyIndexStringList) Reset ¶ added in v0.0.6
func (x *KeyIndexStringList) Reset()
func (*KeyIndexStringList) String ¶ added in v0.0.6
func (x *KeyIndexStringList) String() string
type Logger ¶ added in v0.0.6
type Logger interface {
Debug(args ...interface{})
Info(args ...interface{})
Warn(args ...interface{})
Error(args ...interface{})
DPanic(args ...interface{})
Panic(args ...interface{})
Fatal(args ...interface{})
Debugf(template string, args ...interface{})
Infof(template string, args ...interface{})
Warnf(template string, args ...interface{})
Errorf(template string, args ...interface{})
DPanicf(template string, args ...interface{})
Panicf(template string, args ...interface{})
Fatalf(template string, args ...interface{})
}
type MappingWalker ¶ added in v0.0.20
type MappingWalker interface {
WalkMappings(prefix string, fn func(key string, value []byte) bool) error
}
MappingWalker is an optional interface a Storer can implement to stream mapping entries in bounded batches instead of materializing the whole mapping index in memory like MapKeys does. The walk stops early when fn returns false. The key passed to fn is stripped of the given prefix.
type Revalidator ¶
type Revalidator struct {
Matched bool
IfNoneMatchPresent bool
IfMatchPresent bool
IfModifiedSincePresent bool
IfUnmodifiedSincePresent bool
IfUnmotModifiedSincePresent bool
NeedRevalidation bool
NotModified bool
IfModifiedSince time.Time
IfUnmodifiedSince time.Time
IfNoneMatch []string
IfMatch []string
RequestETags []string
ResponseETag string
}
type SetStorer ¶ added in v0.0.20
type SetStorer interface {
// AddToSet adds members to the set stored at key, extending the set
// lifetime to at least the given duration when it is positive, without
// shortening a longer remaining lifetime.
AddToSet(key string, members []string, duration time.Duration) error
// GetSet returns all members of the set stored at key.
GetSet(key string) []string
// WalkSets visits every set whose key matches the prefix. The walk stops
// early when fn returns false. The key passed to fn is stripped of the
// given prefix.
WalkSets(prefix string, fn func(key string, members []string) bool) error
}
SetStorer is an optional interface a Storer can implement to store a set of members under a key natively, instead of a separator-joined string value that must be fully read and rewritten on every addition.
type StorageMapper ¶
type StorageMapper struct {
Mapping map[string]*KeyIndex `` /* 155-byte string literal not displayed */
// contains filtered or unexported fields
}
func DecodeMapping ¶
func DecodeMapping(item []byte) (*StorageMapper, error)
func (*StorageMapper) Descriptor
deprecated
added in
v0.0.6
func (*StorageMapper) Descriptor() ([]byte, []int)
Deprecated: Use StorageMapper.ProtoReflect.Descriptor instead.
func (*StorageMapper) GetMapping ¶ added in v0.0.6
func (x *StorageMapper) GetMapping() map[string]*KeyIndex
func (*StorageMapper) ProtoMessage ¶ added in v0.0.6
func (*StorageMapper) ProtoMessage()
func (*StorageMapper) ProtoReflect ¶ added in v0.0.6
func (x *StorageMapper) ProtoReflect() protoreflect.Message
func (*StorageMapper) Reset ¶ added in v0.0.6
func (x *StorageMapper) Reset()
func (*StorageMapper) String ¶ added in v0.0.6
func (x *StorageMapper) String() string
type Storer ¶
type Storer interface {
MapKeys(prefix string) map[string]string
ListKeys() []string
Get(key string) []byte
Set(key string, value []byte, duration time.Duration) error
Delete(key string)
DeleteMany(key string)
Init() error
Name() string
Uuid() string
Reset() error
// Multi level storer to handle fresh/stale at once
GetMultiLevel(key string, req *http.Request, validator *Revalidator) (fresh *http.Response, stale *http.Response)
SetMultiLevel(baseKey, variedKey string, value []byte, variedHeaders http.Header, etag string, duration time.Duration, realKey string) error
}
func GetRegisteredStorer ¶
func GetRegisteredStorers ¶
func GetRegisteredStorers() []Storer