Versions in this module Expand all Collapse all v4 v4.0.0 Sep 21, 2026 Changes in this version + const CacheControlHeader + const CacheHeader + const DefaultCacheTTL + const DefaultCleanupInterval + const DefaultMaxCacheSize + const DefaultStaleMapTTL + const ProxyDateHeader + var Clock = func() time.Time + var ErrNotFoundInCache = errors.New("not found in cache") + var Writes sync.WaitGroup + func IsDebugLogging() bool + func SetDebugLogging(b bool) + func SetDefaultMetrics(m Metrics) + func SetLogger(log *logger.Logger) + type Cache interface + Freshen func(res *Resource, keys ...string) error + Header func(key string) (Header, error) + Invalidate func(keys ...string) + Retrieve func(key string) (*Resource, error) + Store func(res *Resource, keys ...string) error + func NewDiskCache(dir string) (Cache, error) + func NewMemoryCache() Cache + func NewVFSCache(fs vfs.VFS) Cache + type CacheConfig struct + CleanupInterval time.Duration + MaxSize int64 + StaleMapTTL time.Duration + TTL time.Duration + func DefaultCacheConfig() *CacheConfig + func (c *CacheConfig) Validate() *CacheConfig + func (c *CacheConfig) WithCleanupInterval(interval time.Duration) *CacheConfig + func (c *CacheConfig) WithMaxSize(size int64) *CacheConfig + func (c *CacheConfig) WithStaleMapTTL(ttl time.Duration) *CacheConfig + func (c *CacheConfig) WithTTL(ttl time.Duration) *CacheConfig + type CacheControl map[string][]string + func ParseCacheControl(input string) (CacheControl, error) + func ParseCacheControlHeaders(h http.Header) (CacheControl, error) + func (cc CacheControl) Add(key, val string) + func (cc CacheControl) Duration(key string) (time.Duration, error) + func (cc CacheControl) Get(key string) (string, bool) + func (cc CacheControl) Has(key string) bool + func (cc CacheControl) String() string + type CacheStats struct + HitCount int64 + ItemCount int + MissCount int64 + StaleCount int + TotalSize int64 + type CleanupResult struct + Duration time.Duration + RemovedBytes int64 + RemovedItems int + RemovedStaleEntries int + type ExtendedCache interface + Cleanup func() CleanupResult + Close func() error + Purge func() error + Stats func() CacheStats + func NewDiskCacheWithConfig(dir string, config *CacheConfig) (ExtendedCache, error) + func NewMemoryCacheWithConfig(config *CacheConfig) ExtendedCache + func NewVFSCacheWithConfig(fs vfs.VFS, config *CacheConfig) ExtendedCache + type Handler struct + Shared bool + func NewHandler(cache Cache, upstream http.Handler) *Handler + func NewHandlerWithOptions(cache Cache, upstream http.Handler, opts *HandlerOptions) *Handler + func NewSharedHandler(cache Cache, upstream http.Handler) *Handler + func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) + func (h *Handler) SetMetrics(m Metrics) + func (h *Handler) Shutdown(ctx context.Context) error + type HandlerOptions struct + Logger *logger.Logger + StaleMarkerTTL time.Duration + type Header struct + StatusCode int + type Key struct + func NewKey(method string, u *url.URL, h http.Header) Key + func NewRequestKey(r *http.Request) Key + func (k Key) ForMethod(method string) Key + func (k Key) String() string + func (k Key) Vary(varyHeader string, r *http.Request) Key + type Metrics interface + RecordCacheEviction func(reason string) + RecordCacheHit func(method string) + RecordCacheMiss func(method string) + RecordCacheSkip func() + RecordCleanupDuration func(durationSeconds float64) + RecordRetrieveOperation func(found bool) + RecordStoreOperation func(success bool) + RecordUpstreamDuration func(method string, status int, durationSeconds float64) + RecordUpstreamError func(errorType string) + SetCacheItemCount func(count int) + SetCacheSize func(sizeBytes int64) + SetCacheStaleCount func(count int) + UpdateCacheStats func(stats CacheStats) + func GetDefaultMetrics() Metrics + type NopMetrics struct + func (NopMetrics) RecordCacheEviction(string) + func (NopMetrics) RecordCacheHit(string) + func (NopMetrics) RecordCacheMiss(string) + func (NopMetrics) RecordCacheSkip() + func (NopMetrics) RecordCleanupDuration(float64) + func (NopMetrics) RecordRetrieveOperation(bool) + func (NopMetrics) RecordStoreOperation(bool) + func (NopMetrics) RecordUpstreamDuration(string, int, float64) + func (NopMetrics) RecordUpstreamError(string) + func (NopMetrics) SetCacheItemCount(int) + func (NopMetrics) SetCacheSize(int64) + func (NopMetrics) SetCacheStaleCount(int) + func (NopMetrics) UpdateCacheStats(CacheStats) + type ReadSeekCloser interface + type Resource struct + RequestTime time.Time + ResponseTime time.Time + func NewResource(statusCode int, body ReadSeekCloser, hdrs http.Header) *Resource + func NewResourceBytes(statusCode int, b []byte, hdrs http.Header) *Resource + func (r *Resource) Age() (time.Duration, error) + func (r *Resource) DateAfter(d time.Time) bool + func (r *Resource) Expires() (time.Time, error) + func (r *Resource) HasExplicitExpiration() bool + func (r *Resource) HasValidators() bool + func (r *Resource) Header() http.Header + func (r *Resource) HeuristicFreshness() time.Duration + func (r *Resource) IsNonErrorStatus() bool + func (r *Resource) IsStale() bool + func (r *Resource) LastModified() time.Time + func (r *Resource) MarkStale() + func (r *Resource) MaxAge(shared bool) (time.Duration, error) + func (r *Resource) MustValidate(shared bool) bool + func (r *Resource) ReceivedAfter(d time.Time) bool + func (r *Resource) RemovePrivateHeaders() + func (r *Resource) SetStoredAt(t time.Time) + func (r *Resource) Status() int + func (r *Resource) StoredAfter(d time.Time) bool + func (r *Resource) Via() string + type Validator struct + Handler http.Handler + func (v *Validator) Validate(req *http.Request, res *Resource) bool Other modules containing this package github.com/soulteary/httpcache-kit github.com/soulteary/httpcache-kit/v2