Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when the remote resource responds with HTTP 404.
Functions ¶
func ResetOriginBackoff ¶
func ResetOriginBackoff()
ResetOriginBackoff ends a running origin pause. Meant for tests, which share the process-wide pause.
func SetHTTPClient ¶
SetHTTPClient overrides the package HTTP client and returns a restore function. This is primarily useful for tests that need a custom transport.
Types ¶
type CacheManager ¶
type CacheManager struct {
// contains filtered or unexported fields
}
func NewCacheManager ¶
func NewCacheManager(dir, manifestPath string, ttl int) (*CacheManager, error)
func (*CacheManager) ClearManifest ¶
func (c *CacheManager) ClearManifest() error
func (*CacheManager) ETagFor ¶
func (c *CacheManager) ETagFor(url string) string
ETagFor returns the cached ETag for the given URL, or an empty string if the URL is not in the manifest yet.
func (*CacheManager) Get ¶
func (c *CacheManager) Get(url string) (string, error)
Get revalidates url against the origin (conditional GET), compiles the body as Markdown, caches the resulting HTML, and returns it.
An entry is revalidated with the origin via ETag/Last-Modified at most every revalidateInterval. When the origin fails, the cached body is served whatever its age (a stale page beats an error page); past TTL this is logged as an ERROR so an origin outage does not go unnoticed.
func (*CacheManager) GetRaw ¶
func (c *CacheManager) GetRaw(url string) (string, error)
GetRaw revalidates url and caches the raw response body (no Markdown compilation). Use this for SML page definitions fetched from a remote repo.
func (*CacheManager) SetRevalidateInterval ¶
func (c *CacheManager) SetRevalidateInterval(d time.Duration)
SetRevalidateInterval changes how long an entry is served without asking the origin (default revalidateInterval; 0 = revalidate on every call).
type FetchResult ¶
func Fetch ¶
func Fetch(url, etag, lastModified string) (*FetchResult, error)
type Manifest ¶
type Manifest struct {
Version int `json:"version"`
Entries map[string]ManifestEntry `json:"entries"`
}
type ManifestEntry ¶
type RateLimitError ¶
RateLimitError is returned for HTTP 429; RetryAfter is the origin's Retry-After (0 if missing or not in seconds).
func (*RateLimitError) Error ¶
func (e *RateLimitError) Error() string