Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 1.38 KB

File metadata and controls

47 lines (35 loc) · 1.38 KB

Cachen

Build Status Coverage Status Go Report Card GoDoc

Golang library that simplify the way you manage the http cache.

Usage

Install the library with:

$ go get github.com/nerac/cachen

Import library into your code with as in the next example:

package main

import (
    "fmt"
    "net/http"
    "github.com/nerac/cachen"
)
func homeHandler(w http.ResponseWriter, r *http.Request) {
    cache := cachen.New()

    etag := "my etag"

    cache.ReusableRequest(true).
    RevalidateEachTime(false).
    IntermediatesAllowed(true).
    MaxAge(5 * SECONDS).
    StaleAllowed(true).
    Etag(etag).
    Bind(w,r)

    fmt.Fprintf(w, "This content is cached 5 seconds by all parties!")
}
func main() {

    http.HandleFunc("/", homeHandler)
    err := http.ListenAndServe(":8080", nil)
    if err != nil {
        log.Fatal("ListenAndServe: ", err)
    }
}