Skip to content

Latest commit

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

httpcache-kit

Go Report Card

RFC7234-compliant HTTP cache handler for Go, with memory and disk backends (via vfs-kit), Cache-Control parsing, and Prometheus metrics. Evolved from lox/httpcache (MIT).

Installation

go get github.com/soulteary/httpcache-kit

Example

package main
import (
"log""net/http""net/http/httputil"
httpcache "github.com/soulteary/httpcache-kit"
)
funcmain() {
proxy:=&httputil.ReverseProxy{
Director: func(r*http.Request) {},
}
handler:=httpcache.NewHandler(httpcache.NewMemoryCache(), proxy)
handler.Shared=truelog.Print("proxy listening on http://localhost:8080")
log.Fatal(http.ListenAndServe(":8080", handler))
}

Disk-backed cache with config:

cache, err:=httpcache.NewDiskCacheWithConfig("/var/cache/myproxy", httpcache.DefaultCacheConfig())
iferr!=nil {
log.Fatal(err)
}
defercache.Close()
handler:=httpcache.NewHandlerWithOptions(cache, proxy, &httpcache.HandlerOptions{Logger: myLogger})

Features

  • RFC7234-compliant caching (with documented caveats)
  • Memory and disk storage (disk uses vfs-kit for VFS abstraction)
  • Configurable TTL, max size, cleanup interval, LRU eviction
  • Optional Prometheus metrics via metrics-kit
  • Optional debug logging via logger-kit

Caveats

  • Conditional requests (e.g. Range) are not cached.

References

About

RFC7234-compliant HTTP cache handler for Go, with memory and disk backends (via vfs-kit), Cache-Control parsing, and Prometheus metrics.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages