Documentation
¶
Index ¶
- Constants
- Variables
- func FetchMetadata(domainID string, method string, url url.URL) ([]string, error)
- func GetVary(headers http.Header) ([]string, error)
- func PurgeMetadata(ctx context.Context, domainID string, url url.URL) error
- func StorageKey(currentURIObject URIObj, meta []string) string
- func StoreMetadata(ctx context.Context, domainID string, method string, url url.URL, ...) (bool, error)
- type Object
- func (c Object) IsEmptyBodyAllowed() bool
- func (c Object) IsMethodAllowed() bool
- func (c Object) IsStatusAllowed() bool
- func (c Object) IsValid() (bool, error)
- func (c Object) PurgeFullPage(ctx context.Context) (bool, error)
- func (c *Object) RetrieveFullPage() error
- func (c Object) StoreFullPage(ctx context.Context, expiration time.Duration) (bool, error)
- type URIObj
Constants ¶
const DefaultMaxSoftExpirationTTL time.Duration = 10 * time.Second // TODO: Make it customizable?
DefaultMaxSoftExpirationTTL - Additional time to avoid cache stampede (max upper bound).
const DefaultMinSoftExpirationTTL time.Duration = 5 * time.Second // TODO: Make it customizable?
DefaultMinSoftExpirationTTL - Additional time to avoid cache stampede (min lower bound).
const FreshSuffix = "/fresh"
FreshSuffix - Used for saving a suffix for handling cache stampede.
Variables ¶
var ErrEmptyValue = errors.New("empty value")
ErrEmptyValue - Error used when no data is available in Redis.
Functions ¶
func FetchMetadata ¶
FetchMetadata - Returns the cache metadata for the requested URL.
func PurgeMetadata ¶
PurgeMetadata - Purges the cache metadata for the requested URL.
func StorageKey ¶
StorageKey - Returns the cache key for the requested URL.
Types ¶
type Object ¶ added in v1.3.1
type Object struct {
ReqID string
AllowedStatuses []int
AllowedMethods []string
CurrentURIObject URIObj
DomainID string
}
Object - Contains cache settings and current cached/cacheable object.
func (Object) IsEmptyBodyAllowed ¶ added in v1.3.1
IsEmptyBodyAllowed - Checks if an empty body is allowed to be cached.
func (Object) IsMethodAllowed ¶ added in v1.3.1
IsMethodAllowed - Checks if a HTTP method is allowed to be cached.
func (Object) IsStatusAllowed ¶ added in v1.3.1
IsStatusAllowed - Checks if a status code is allowed to be cached.
func (Object) PurgeFullPage ¶ added in v1.3.1
PurgeFullPage - Deletes the whole page response from cache.
func (*Object) RetrieveFullPage ¶ added in v1.3.1
RetrieveFullPage - Retrieves the whole page response from cache.
type URIObj ¶
type URIObj struct {
URL url.URL
Method string
StatusCode int
RequestHeaders http.Header
ResponseHeaders http.Header
Content [][]byte
Stale bool
}
URIObj - Holds details about the response.
func (URIObj) GetHeadersChecksum ¶ added in v1.3.1
GetHeadersChecksum - Returns a SHA256 based on the HTTP Request Headers.
func (URIObj) HasRangeRequest ¶ added in v1.3.1
HasRangeRequest - Checks if the incoming request asked for a byte range. Range requests must always bypass the cache: this cache stores/serves whole bodies, so returning a full cached body for a ranged request would be a wrong response (wrong status code and bytes) to the client.
func (URIObj) IsPartialContent ¶ added in v1.3.1
IsPartialContent - Checks if the response is a partial content response (206, or carrying Content-Range). Such responses must never be stored as if they were the full resource, or later non-range requests would be served truncated bytes.
func (URIObj) IsStorableBySharedCache ¶ added in v1.3.3
IsStorableBySharedCache - Checks whether a shared cache may store the response at all (RFC 9111 §3), whatever TTL it would otherwise get (this also covers the negative TTL override):
- no-store, private (incl. private="...") and no-cache forbid it, see ttl.ForbidsStoring;
- a response to a request carrying Authorization is only storable when the response explicitly allows it with public, s-maxage or must-revalidate (RFC 9111 §3.5).