Documentation
¶
Overview ¶
Package s3cache implements a Caddy virtual filesystem (`caddy.fs.s3cache`) that serves objects from an S3 bucket through a local disk cache.
It exists because `file_server` on a plain S3 filesystem costs three round trips per file (HEAD for Stat, GET for Open, and a second GET when http.ServeContent seeks back to the start) and nothing is remembered between requests. This module fetches an object once with a single GET, keeps it on local disk, answers Stat and Open from that copy, and revalidates with If-None-Match after a configurable interval. A hot object is served without any S3 request; a cold object costs one.
Index ¶
Constants ¶
const ( DefaultCacheMaxSize int64 = 512 << 20 // 512 MiB DefaultRevalidateAfter = 60 * time.Second DefaultNegativeTTL = 30 * time.Second DefaultKeepalive = 25 * time.Second DefaultMaxIdleConns = 16 )
Defaults applied by Provision when a field is zero.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FS ¶
type FS struct {
// Bucket is the S3 bucket name (required).
Bucket string `json:"bucket,omitempty"`
// Region is the AWS region of the bucket. Empty falls back to the SDK's
// default resolution (AWS_REGION and friends).
Region string `json:"region,omitempty"`
// Endpoint overrides the S3 endpoint, for S3-compatible stores.
Endpoint string `json:"endpoint,omitempty"`
// UsePathStyle switches to path-style addressing (needed by most
// S3-compatible test servers).
UsePathStyle bool `json:"use_path_style,omitempty"`
// Prefix is prepended to every key. A filesystem path `a/b.jpg` with
// prefix `media/` reads the object `media/a/b.jpg`.
Prefix string `json:"prefix,omitempty"`
// CacheDir holds the cached object bodies. Default: a directory below
// os.TempDir(). The directory is emptied when the module is provisioned,
// because the in-memory index starts empty and would otherwise leak files.
CacheDir string `json:"cache_dir,omitempty"`
// CacheMaxSize bounds the cache in bytes; least recently used objects are
// evicted first. Default 512 MiB.
CacheMaxSize int64 `json:"cache_max_size,omitempty"`
// RevalidateAfter is how long a cached object is served without asking S3
// whether it changed. After that, the next access sends a conditional GET
// (If-None-Match); a 304 costs one round trip and no body. Default 60s.
RevalidateAfter caddy.Duration `json:"revalidate_after,omitempty"`
// NegativeTTL is how long a missing key stays missing without asking S3
// again. Default 30s.
NegativeTTL caddy.Duration `json:"negative_ttl,omitempty"`
// Keepalive is the interval of a background HeadBucket request that keeps
// a TLS connection to S3 open, so the first request after a quiet period
// does not pay for a new handshake. 0 disables it. Default 25s.
Keepalive caddy.Duration `json:"keepalive,omitempty"`
// MaxIdleConns bounds the pooled connections to S3. Default 16.
MaxIdleConns int `json:"max_idle_conns,omitempty"`
// contains filtered or unexported fields
}
FS is a Caddy virtual filesystem backed by an S3 bucket with a local disk cache.
func (FS) CaddyModule ¶
func (FS) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*FS) UnmarshalCaddyfile ¶
UnmarshalCaddyfile implements caddyfile.Unmarshaler.
filesystem <name> s3cache {
bucket <name>
region <region>
endpoint <url>
use_path_style
prefix <key-prefix>
cache_dir <path>
cache_max_size <bytes>
revalidate_after <duration>
negative_ttl <duration>
keepalive <duration>|off
max_idle_conns <n>
}