cachecontrol

package module
v0.0.0-...-01b38e1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2018 License: MIT Imports: 8 Imported by: 0

README

cache-control

cache-control middleware adds ETag header (md5 of the content) and Cache-Control header

sample usage

Using chi router, we register this middleware before a http.FileServer:

fs := http.Dir(`./assets`)
assetServer := http.FileServer(fs)
rt.Route("/assets/*", func(rt chi.Router) {
	rt.Use(cachecontrol.CacheControl(
		fs,
		cachecontrol.StripPrefix("/assets")))
	rt.Get(
		"/*",
		http.StripPrefix("/assets", assetServer).ServeHTTP)
})

TODO

  • dirwatch can be used for watching directories of assets (next).
  • more tests

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheControl

func CacheControl(fs http.FileSystem, options ...Option) func(http.Handler) http.Handler

CacheControl is a middleware for adding ETag and Cache-Control headers, and checks If-None-Match client header

func DevelopmentMode

func DevelopmentMode()

DevelopmentMode checks for expired entries every time.Millisecond * 10

Types

type Option

type Option func(ccoptions) ccoptions

Option .

func IsPrivate

func IsPrivate(isPrivate bool) Option

IsPrivate marks "Cache-Control" as private

func IsWeak

func IsWeak(isWeak bool) Option

IsWeak sets if the generated ETag should be a weak one

func MaxAge

func MaxAge(maxAge int) Option

MaxAge sets "max-age" in "Cache-Control" header, in seconds

func StripPrefix

func StripPrefix(stripPrefix string) Option

StripPrefix .

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL